From patchwork Thu Sep 21 10:45:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0226FE70718 for ; Thu, 21 Sep 2023 11:01:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A74396B01F9; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 849F76B01FF; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EFF06B01B1; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 211D26B01FF for ; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C48F41CADFA for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.30.682A7F0 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf30.hostedemail.com (Postfix) with ESMTP id 4398A8003B for ; Thu, 21 Sep 2023 11:00:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=J3l9ojEs; spf=none (imf30.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695294056; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=qZGXn0GjyOVEXezGJP51+kNBqwjTUdfIFaStjMYeBB0=; b=oYs6gHNxHgpXPSgq5hMmbz9k3pXaa3dJEBlYmTR2Ct1zlC5dMB4HGvSXF1dQhTmJ89yJJ7 gH2QIxF9k9+6orMDUma8zFS55jYRlOiaECgt4GKWopFo7jZjHZs5MSuQtXURkIqXERWdk+ 31UvuyuzE1pRtZX30ygmm+AMKSotdkk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294056; a=rsa-sha256; cv=none; b=rY2KyAmc328+yrdSXodBUCWA4WHc64fdNznWrjZANFN7h1lPvuKhSlZElzfHG72GCx1DAE ebN9SB807xx+NQ0KrB3FNxzRYW1Yp9iR8H+hbNJwOziWLCPVzgwx3PGP+j6LJ8U2KsMl0D W8o841GIb30ESszTuKn5wJ7q1jU9ycc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=J3l9ojEs; spf=none (imf30.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=qZGXn0GjyOVEXezGJP51+kNBqwjTUdfIFaStjMYeBB0=; b=J3l9ojEsbOGfPBtXP86sKEB8XD wbzSG4aPsf/4A5xghKK1aLECSnRsMOcpoiSnvd63aq9cUDsSIAj/CsSrKK09Hyk2kkvMgZfSQv7yH 7+qwuJMzgaS+VquY+Dk2C3nMddqvpeV0y/d+DUOy9f/1nYZc+BjX4LHbGCpWaG6O7dSib80z+sUbC XS1mZOT+TL4TFhx49AGJI5Bjf9VsLws4Ut1lv7OwVlt+aL1rUSMPKbGuSP6pS8Aj3Ot20JEMTVKa4 dfY4jjvCONrlqr6VrOFn17LlGeWlaVA0UV2Zp+ga08hbyJd+ITfLggX4wfh4/LCL/CqQ+3j6VXt5K A5s9FrlA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qjHQN-00FJvs-1M; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id ED74230058C; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105248.048643656@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:11 +0200 From: peterz@infradead.org To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v3 06/15] futex: FLAGS_STRICT References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-wake-0.patch X-Stat-Signature: nrtihqg3gz9k41epeo3bwx9oosrcabie X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4398A8003B X-Rspam-User: X-HE-Tag: 1695294055-448986 X-HE-Meta: U2FsdGVkX19HLySZ44cRHcCEIwXdA+3NOs5GTdOELFPr2nuRtxmpoNQ2CjY7Kr4j5ooVc9jqEk7ZXtbjXynFP29OtGfYoa61YfwzsJ3mGEPzKSBUVxvDQf+WmaE4z9pbU07r5s6nSutyJPj4/h/F9yijPvgLkCn49aLWCrci1gH4t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RDn7+qdfhjNXCrUpCr1ofm8FKQyOISk3KO2OJlNzvpYenlz+Xz12caaqYE+gIq3lkTHHBUQjzFvLSyPkrucRuPG7mUr6Ab62Zs8pTKP83pr7Si5nBiIoUcGv1JPGM6k/X604o8vMtLgQ9scALH+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The current semantics for futex_wake() are a bit loose, specifically asking for 0 futexes to be woken actually gets you 1. Adding a !nr check to sys_futex_wake() makes that it would return 0 for unaligned futex words, because that check comes in the shared futex_wake() function. Adding the !nr check there, would affect the legacy sys_futex() semantics. Hence frob a flag :-( Suggested-by: André Almeida Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -17,25 +17,26 @@ * Futex flags used to encode options to functions and preserve them across * restarts. */ -#define FLAGS_SIZE_8 0x00 -#define FLAGS_SIZE_16 0x01 -#define FLAGS_SIZE_32 0x02 -#define FLAGS_SIZE_64 0x03 +#define FLAGS_SIZE_8 0x0000 +#define FLAGS_SIZE_16 0x0001 +#define FLAGS_SIZE_32 0x0002 +#define FLAGS_SIZE_64 0x0003 -#define FLAGS_SIZE_MASK 0x03 +#define FLAGS_SIZE_MASK 0x0003 #ifdef CONFIG_MMU -# define FLAGS_SHARED 0x10 +# define FLAGS_SHARED 0x0010 #else /* * NOMMU does not have per process address space. Let the compiler optimize * code away. */ -# define FLAGS_SHARED 0x00 +# define FLAGS_SHARED 0x0000 #endif -#define FLAGS_CLOCKRT 0x20 -#define FLAGS_HAS_TIMEOUT 0x40 -#define FLAGS_NUMA 0x80 +#define FLAGS_CLOCKRT 0x0020 +#define FLAGS_HAS_TIMEOUT 0x0040 +#define FLAGS_NUMA 0x0080 +#define FLAGS_STRICT 0x0100 /* FUTEX_ to FLAGS_ */ static inline unsigned int futex_to_flags(unsigned int op) Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/kernel/futex/syscalls.c @@ -333,7 +333,7 @@ SYSCALL_DEFINE4(futex_wake, if (!futex_validate_input(flags, mask)) return -EINVAL; - return futex_wake(uaddr, flags, nr, mask); + return futex_wake(uaddr, FLAGS_STRICT | flags, nr, mask); } #ifdef CONFIG_COMPAT Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/kernel/futex/waitwake.c @@ -155,6 +155,9 @@ int futex_wake(u32 __user *uaddr, unsign if (unlikely(ret != 0)) return ret; + if ((flags & FLAGS_STRICT) && !nr_wake) + return 0; + hb = futex_hash(&key); /* Make sure we really have tasks to wakeup */