Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp74967ybk; Tue, 19 May 2020 15:58:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwITIEVG4sX/iK6tvZVAPpkOODQzEWKubXh4/i+cMFPztXMHjnBpro+aQfSkhJRUPcvRSIB X-Received: by 2002:a50:88c6:: with SMTP id d64mr929671edd.324.1589929106082; Tue, 19 May 2020 15:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589929106; cv=none; d=google.com; s=arc-20160816; b=ac/vPTZPLjxEz2N7PY/mFdKYmaOUEk/DkV29uTBWC1O5vpuZEHgL7pKFhmdQTfPFhp 9GKWZeuxhxcYeK1O+GvAIUtfxGq8in6VMigbn2QveezJPXnBkUMT/1DggPyiX4b0uPu2 7cIvLaOJbITZ+Se9c2+/H/aJdsLSZ1b9VQxM62+8V2bbCLLDyuKmkWKOuDm4Wcc/gYND sQJAP/x/mUOsMwSZCt7SCDthyz3AwqyIBjbcMFJcQgBi1QadwPt6ICCs14ndmvBfy8Z1 VPBCblyAv46fxQV/HOB9qazLZTP+hPdg19VySR5sQLlUyXqDNr8zDhbnvJWCYg1qD4FS cq1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=4Hc4gfH1jR3w9mH1iMbTJbnLS9mK/M2i9zKWa1KO47g=; b=klRdLE7YvVvBH/u599ZG9jnva+fng0EE/CosZVXDYGQklXRDS0nVyKgzl1fwnpzNzH QoSZ5WeSwmIgb6NIVTwAhOjWaTM0fEEShVBfMiyig++9a7lLXzJpFTFeYqjVjQMwnDR6 bVmaWCDffuWVLbQ4nPURHNU0vlxRPDoxCxh1Oe4bV33fM+Y94SMaF67lPXdNvSg0pobf cQEqVfpk4VnXXHCchPjsGy33wT14tEvlFrsIbzpRGCevJA7cHnkFdmdMLDen07mfOTIo fMR8jHuJtuqtREBol2rojyW5G3NRMgUX5eDpmVFep+FIlMc+l1lbNXCxWyZ47afwSxiM l0NA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd22si450270edb.557.2020.05.19.15.57.51; Tue, 19 May 2020 15:58:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727801AbgESWxb (ORCPT + 99 others); Tue, 19 May 2020 18:53:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbgESWxb (ORCPT ); Tue, 19 May 2020 18:53:31 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E352DC061A0E; Tue, 19 May 2020 15:53:30 -0700 (PDT) Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jbB6y-0003lX-Nc; Wed, 20 May 2020 00:53:25 +0200 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 30B81100D00; Wed, 20 May 2020 00:53:24 +0200 (CEST) From: Thomas Gleixner To: Konstantin Khlebnikov , linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Darren Hart Cc: Maxim Samoylov , Linus Torvalds , linux-api@vger.kernel.org Subject: Re: [PATCH] futex: send SIGBUS if argument is not aligned on a four-byte boundary In-Reply-To: <158955700764.647498.18025770126733698386.stgit@buzz> References: <158955700764.647498.18025770126733698386.stgit@buzz> Date: Wed, 20 May 2020 00:53:24 +0200 Message-ID: <87sgfv5yfv.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Konstantin Khlebnikov writes: > Userspace implementations of mutexes (including glibc) in some cases > retries operation without checking error code from syscall futex. > This is good for performance because most errors are impossible when > locking code trusts itself. This argument is blantantly wrong. It's the justification for bad programming. Code ignoring error returns is simply buggy. > Some errors which could came from outer code are handled automatically, > for example invalid address triggers SIGSEGV on atomic fast path. > > But one case turns into nasty busy-loop: when address is unaligned. > futex(FUTEX_WAIT) returns EINVAL immediately and loop goes to retry. Why is that something the kernel has to care about? The kernel returns EINVAl as documented and when user space decides to ignore then it goes to retry for a full timeslice for nothing. You have to come up with a better argument why we want to send a signal here. Along with an argument why SIGBUS is the right thing when a user space fast path violation results in a SIGSEGV as you stated above. Plus a patch which documents this change in the futex man page. > Example which loops inside second call rather than hung peacefully: > > #include > #include > > int main(int argc, char **argv) > { > char buf[sizeof(pthread_mutex_t) + 1]; > pthread_mutex_t *mutex = (pthread_mutex_t *)(buf + 1); > > pthread_mutex_init(mutex, NULL); > pthread_mutex_lock(mutex); > pthread_mutex_lock(mutex); > } And this broken code is a kernel problem because? > It seems there is no practical usage for calling syscall futex for > unaligned address. This may be only bug in user space. Let's help and > handle this gracefully without adding extra code on fast path. How does that help? Are you going to stick SIGBUS in _ALL_ syscalls which might be retried in a loop just because user space fails to evaluate the error code properly? You have to come up with a better argument to justify this change. > This patch sends SIGBUS signal to slay task and break busy-loop. I'm pretty sure that I asked you to read and follow documentation before. If I did not: git grep 'This patch' Documentation/process/ Thanks, tglx