/****************************************************************************** ******************************************************************************* ** ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. ** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. ** ** This copyrighted material is made available to anyone wishing to use, ** modify, copy, or redistribute it subject to the terms and conditions ** of the GNU General Public License v.2. ** ******************************************************************************* ******************************************************************************/ /* * midcomms.c * * This is the appallingly named "mid-level" comms layer. * * Its purpose is to take packets from the "real" comms layer, * split them up into packets and pass them to the interested * part of the locking mechanism. * * It also takes messages from the locking layer, formats them * into packets and sends them to the comms layer. */ #include "dlm_internal.h" #include "lowcomms.h" #include "config.h" #include "lock.h" #include "midcomms.h" static void copy_from_cb(void *dst, const void *base, unsigned offset, unsigned len, unsigned limit) { unsigned copy = len; if ((copy + offset) > limit) copy = limit - offset; memcpy(dst, base + offset, copy); len -= copy; if (len) memcpy(dst + copy, base, len); } /* * Called from the low-level comms layer to process a buffer of * commands. * * Only complete messages are processed here, any "spare" bytes from * the end of a buffer are saved and tacked onto the front of the next * message that comes in. I doubt this will happen very often but we * need to be able to cope with it and I don't want the task to be waiting * for packets to come in when there is useful work to be done. */ int dlm_process_incoming_buffer(int nodeid, const void *base, unsigned offset, unsigned len, unsigned limit) { union { unsigned char __buf[DLM_INBUF_LEN]; /* this is to force proper alignment on some arches */ union dlm_packet p; } __tmp; union dlm_packet *p = &__tmp.p; int ret = 0; int err = 0; uint16_t msglen; uint32_t lockspace; while (len > sizeof(struct dlm_header)) { /* Copy just the header to check the total length. The message may wrap around the end of the buffer back to the start, so we need to use a temp buffer and copy_from_cb. */ copy_from_cb(p, base, offset, sizeof(struct dlm_header), limit); msglen = le16_to_cpu(p->header.h_length); lockspace = p->header.h_lockspace; err = -EINVAL; if (msglen < sizeof(struct dlm_header)) break; if (p->header.h_cmd == DLM_MSG) { if (msglen < sizeof(struct dlm_message)) break; } else { if (msglen < sizeof(struct dlm_rcom)) break; } err = -E2BIG; if (msglen > dlm_config.ci_buffer_size) { log_print("message size %d from %d too big, buf len %d", msglen, nodeid, len); break; } err = 0; /* If only part of the full message is contained in this buffer, then do nothing and wait for lowcomms to call us again later with more data. We return 0 meaning we've consumed none of the input buffer. */ if (msglen > len) break; /* Allocate a larger temp buffer if the full message won't fit in the buffer on the stack (which should work for most ordinary messages). */ if (msglen > sizeof(__tmp) && p == &__tmp.p) { p = kmalloc(dlm_config.ci_buffer_size, GFP_NOFS); if (p == NULL) return ret; } copy_from_cb(p, base, offset, msglen, limit); BUG_ON(lockspace != p->header.h_lockspace); ret += msglen; offset += msglen; offset &= (limit - 1); len -= msglen; dlm_receive_buffer(p, nodeid); } if (p != &__tmp.p) kfree(p); return err ? err : ret; } tion value='35'>35space:mode:
authorThomas Gleixner <tglx@linutronix.de>2017-01-31 23:58:38 +0100
committerIngo Molnar <mingo@kernel.org>2017-02-01 08:37:27 +0100
commitdd86e373e09fb16b83e8adf5c48c421a4ca76468 (patch)
tree55703c2ea8584e303e342090614e0aab3509ab21 /net/ipv6/ndisc.c
parent0b3589be9b98994ce3d5aeca52445d1f5627c4ba (diff)
perf/x86/intel/rapl: Make package handling more robust
The package management code in RAPL relies on package mapping being available before a CPU is started. This changed with: 9d85eb9119f4 ("x86/smpboot: Make logical package management more robust") because the ACPI/BIOS information turned out to be unreliable, but that left RAPL in broken state. This was not noticed because on a regular boot all CPUs are online before RAPL is initialized. A possible fix would be to reintroduce the mess which allocates a package data structure in CPU prepare and when it turns out to already exist in starting throw it away later in the CPU online callback. But that's a horrible hack and not required at all because RAPL becomes functional for perf only in the CPU online callback. That's correct because user space is not yet informed about the CPU being onlined, so nothing caan rely on RAPL being available on that particular CPU. Move the allocation to the CPU online callback and simplify the hotplug handling. At this point the package mapping is established and correct. This also adds a missing check for available package data in the event_init() function. Reported-by: Yasuaki Ishimatsu <yasu.isimatu@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sebastian Siewior <bigeasy@linutronix.de> Cc: Stephane Eranian <eranian@google.com> Cc: Vince Weaver <vincent.weaver@maine.edu> Fixes: 9d85eb9119f4 ("x86/smpboot: Make logical package management more robust") Link: http://lkml.kernel.org/r/20170131230141.212593966@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'net/ipv6/ndisc.c')