From patchwork Mon Oct 17 14:40:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 3482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1487555wrs; Mon, 17 Oct 2022 07:42:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4oI6yVfk7UxIBIenTdscnCXOcK4E4jnat7MXt1omSBVMoBW2JaKVSGKWyQnZpMoz+cfTAI X-Received: by 2002:a17:907:7e9e:b0:78d:f3b0:fc78 with SMTP id qb30-20020a1709077e9e00b0078df3b0fc78mr8971623ejc.478.1666017767708; Mon, 17 Oct 2022 07:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666017767; cv=none; d=google.com; s=arc-20160816; b=ClmyPSRCEWwIh8nrTYH6WKaKdx3Irb3cdBf3T6580L/M4afnO9iYlVHZvGw+Z0+kYU 3EAEinVoy93sKogXvDVS5TfOfL4g9OBS2z7Yy/0McZ5YzXToJ8ZGIcuVpTREv2SOkl9r eCK0sW3na8SbKb2iaTaNODXh8n2fSjshkyIor0GnhERF5WVh54nVegNK32/PHLXXzC7v 0/+oQ7lwKjgoXEsI6rvKYFndJubMw4lNpXB8aKr6MJIPMK3OKqh/EJ3H7LZnODVUZQm3 6pTJXFLyJA0m+XWEpvfO8lyNKQc6LBiEav0PDmRZiz8vI/mIvet0AEG0HfuWRwbkD960 3Ljw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fGzz9vQihkHLYuMDwQK6thgYE3qPewiwBTfTU2VGOHA=; b=gsEXcfTp0aquYrGrcDak42gywCfzyvucf/HG3NSldt/IJQdojMSyssFz7O+uZB5wu9 ZCc52QkVVTLUnlFBe7koyd8o93jOgpp65L6cOKFQOYQHWEVrNOA3rjDPusGaWZt06aMp sx3lbmv4sLS2Mf6/4XTIj/fkm/z6ABKhEj48tTLIVAVcApdNvSoPYWTIW+1Qf1bD7guA tjyx8zmIlTnjGf4kSebcZWMjKuSUikkZnOZyv4dSMpWKC6fE2FAtjJ5AZ9NCViWyvROA hIWdPwIlf4vPzreWlFgvmeoL/Z8XgEuKZLDQqVzHkr1FWGadHYEONqTD4bcy1T8DbzG1 EmGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GGI054dt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c24-20020a50d658000000b0045cb9cf913csi8614292edj.424.2022.10.17.07.42.23; Mon, 17 Oct 2022 07:42:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GGI054dt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbiJQOlY (ORCPT + 99 others); Mon, 17 Oct 2022 10:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbiJQOlW (ORCPT ); Mon, 17 Oct 2022 10:41:22 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83756612F for ; Mon, 17 Oct 2022 07:41:20 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id b12so16373671edd.6 for ; Mon, 17 Oct 2022 07:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fGzz9vQihkHLYuMDwQK6thgYE3qPewiwBTfTU2VGOHA=; b=GGI054dt/nH/X5fLQ6HzXMyw76tZaZ/ExJKRpHQhcyS3kGKNkKsLX6YHP0m6RAkZA3 ZcrEaUZC4Ij19TF2/y3zLlFEwlJlzW07A27qPq/155DDEIY4B+D/hmcMxdZ7f+gZSdMC sArwLPCQlMiPiME5Z+MYVTT0aUFm+aNChRxEY5zquAK0t+OOPp7SsgXJvl9/zaNA/1f8 6PcUlpst1jSxVyhPKJdp3qBs9xH9+G7sAh1YprxTDU1Ohe8aLaJa2VUfDi5u+tYtc9VB eDEoerRLObfDSNt7Sxv9pckdIVRx/3oNLZFUnX6Nh5jZIEt7ek7vibQNpfrwoT4qzgH+ NHXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fGzz9vQihkHLYuMDwQK6thgYE3qPewiwBTfTU2VGOHA=; b=ojAspNMb4L46kEw19r6a2AagvkgSlA9T/FSVf1yznFNBI/rDhs61Tn598w5beJoxHt f/TD78mUvw3vHafZI/D+0rcApNHB8RFeLSROOzV2T/9PnWeNVQDBX0qV50P7+fNO1KmE Ffr4mwLBkGtreZ40TwRJbMVbhSaBWOX7MNCT9qm3xt7I8dQl44ex38HhYehSp8Ssf3Mm 8JZY6d4/Q9c99TefITs9Sysmh+UDwzFIrtNEUwg5dSBLr2xVwrsknAUQ/UyKGLLj9di4 3psPRsBWgHG882P0TGDMqcEE2np3S58wRbhDr7rayHhVyjLMYBT6Ho7d5pJVSnZY71T1 hTKQ== X-Gm-Message-State: ACrzQf1/jWVdhAmKjm423nblyeCbZBMiqblyuZZnWWgMpFu/6WBzvI1S nVrztzAfofakZgQfO5kI45kA88Kg/ZlP5A== X-Received: by 2002:a05:6402:2546:b0:45d:8bff:7afc with SMTP id l6-20020a056402254600b0045d8bff7afcmr5571700edb.302.1666017678387; Mon, 17 Oct 2022 07:41:18 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id dn2-20020a05640222e200b00459cf672a65sm7469144edb.71.2022.10.17.07.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 07:41:18 -0700 (PDT) From: Uros Bizjak To: linux-kernel@vger.kernel.org Cc: Uros Bizjak , "Eric W. Biederman" Subject: [PATCH RESEND 1/2] ucount: Fix atomic_long_inc_below argument type Date: Mon, 17 Oct 2022 16:40:48 +0200 Message-Id: <20221017144049.3404-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221017144049.3404-1-ubizjak@gmail.com> References: <20221017144049.3404-1-ubizjak@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746946246660709024?= X-GMAIL-MSGID: =?utf-8?q?1746946246660709024?= The type of u argument of atomic_long_inc_below should be long to avoid unwanted truncation to int. Fixes: f9c82a4ea89c ("Increase size of ucounts to atomic_long_t") Signed-off-by: Uros Bizjak Cc: "Eric W. Biederman" --- kernel/ucount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/ucount.c b/kernel/ucount.c index ee8e57fd6f90..74f5b4959feb 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -212,7 +212,7 @@ void put_ucounts(struct ucounts *ucounts) } } -static inline bool atomic_long_inc_below(atomic_long_t *v, int u) +static inline bool atomic_long_inc_below(atomic_long_t *v, long u) { long c, old; c = atomic_long_read(v); From patchwork Mon Oct 17 14:40:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 3483 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1487848wrs; Mon, 17 Oct 2022 07:43:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Jk5TX82+yW0nZxLOiRZxE2u9R77Cpl6gaqx4ng0hb6djvgQ8iGi+2hHDGXJ4m9a0hKs5F X-Received: by 2002:aa7:c751:0:b0:459:b0e1:4ad7 with SMTP id c17-20020aa7c751000000b00459b0e14ad7mr10678232eds.193.1666017807529; Mon, 17 Oct 2022 07:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666017807; cv=none; d=google.com; s=arc-20160816; b=lXluFr7t8TgK7uWnlsvYiqy+qHnd5ustUVPsTXzYlYJ4inCcIHWBpt5TitjB0Yt0k2 s67q3OX7s89vRITsTXY0YmlQ7KyymZo9B7lQS3ABb6xfUiG4soELlNprALwapp7MyFGk vJxfuhzQgeJ3q67w0oKCbZsJfFX1Hqa4foFCpZIDMXcb7mNN26ls9nA4iPrsdRpqTYpE vhYv/UhN8VffHTNEMYWJPSkOsS8+a9DxMTHpuv0UlRQSr2QY6V4Wh8mpuxwKGacPGopr PYNQin0j/K7FEBZOVtZFe+/CheEWi8JC25PCuChUPGyuleqlWcZO/491qMyONXw8A9Gs f6zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HuBb5ljQMpmcyaTrGqF1Fy74D+G132DrFCMrIoW3IlA=; b=mQ61LzT+WA4+wUBpoJ5uWl8QJXqJKOxa7S/uX9ycv4EuhVWw20Y+xtvHmBR8ZSOFrw sGBbYE+Q9oi7JxWCITWppLIGOmnRobOPR18v/olHOsR1NY+136iXWJKEmq29TZLO4v1Z IoUnzXAsavgNXCU4uBQrj4Dr4Qh/F9JSU7u9xFCm27DhLzL1rgOc5h5vzVzRGv1UqK8u XmUC1G9TEJhYUd/DP3Hm0qy3Au1RZ+6+8N2ofhnnJXevDYEjXoHX7e2nkeap8T1lncg6 NC4QnIsDa4n2adKmU8FM7vJTxrIkbVJt8YRmWmOFsSemK8+pd4VoxBoq0NN0TSWC2nCz pIdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YfHjKFir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a170906528700b00783df65ae5esi8805828ejm.683.2022.10.17.07.43.02; Mon, 17 Oct 2022 07:43:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YfHjKFir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230482AbiJQOl1 (ORCPT + 99 others); Mon, 17 Oct 2022 10:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbiJQOlY (ORCPT ); Mon, 17 Oct 2022 10:41:24 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6C7A52455 for ; Mon, 17 Oct 2022 07:41:22 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id 13so25467954ejn.3 for ; Mon, 17 Oct 2022 07:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HuBb5ljQMpmcyaTrGqF1Fy74D+G132DrFCMrIoW3IlA=; b=YfHjKFirxF/uU5tvjOiYI8MDgrsuFH+rzZTctvdHoxu4J5uIvM5uNDryofSIuBCPOS rEc+icCdKPeWSz1RxXEmt/GDRj6VikjonJjpt6v44MXBG0DaB0jpUM0kg/CoZKFGLbme AIyTSw1RRcGoVlElAhPDP9KyGBshifi/VQ2iH/6aH4hWQEvD2rbMbuUeqr1/b5cqOJp9 TQHxZEcyxEdOzX0PNyvZJ0qjJNjxvDNAMD/pQ64OxsaZUnF/BKRt0nekFtLkO8D8FWus ed9aqWODkE/P7db8UCQGjAXBW27ouhAhP9fVZ+W2a6TZZ4S3p43X2/ZBTih/5qYVsOJZ CRkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HuBb5ljQMpmcyaTrGqF1Fy74D+G132DrFCMrIoW3IlA=; b=b0eFek+i0BIz+QsrHCH2jmCRxiDwJ/JKuA/3AQJQ5ecs3UhRS7O/gYLitFZq41GGsH HY+vfMD5+mTZ4Rvm0XU5WXmQQFJVzAuIcWlqo3AWAmmfZ0NWD1lEBjRxMqJb9gsRtdMx TnZKMHsFDAKt7ywBELWYfGCSN0I8Hf8FpQVbZoRmHpSutCpn5ETZNhNAaCPnKgtzPgm5 L78ZRtBE2xwLy0FSfnQIgYEmWi31XHOxgQ5nh7W/7uU+Y1I7/AtmJLYwWUrM1/rfn263 MFdWxWYTp3IJT4eUlvzI7/d8DISO5VowXIoVLTE6MFDzYnpxKV8E837KbVNryMH/yufy LC4A== X-Gm-Message-State: ACrzQf1d5P3kF0fMCWHZYNYlnZDyxQy5hyX27z1y7gjW1L5e0IwJcOf2 iITaa70zfex0uBJd5nOq8Nx16Rw+NU+yGg== X-Received: by 2002:a17:907:70b:b0:740:ef93:2ffb with SMTP id xb11-20020a170907070b00b00740ef932ffbmr8748604ejb.93.1666017680684; Mon, 17 Oct 2022 07:41:20 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id dn2-20020a05640222e200b00459cf672a65sm7469144edb.71.2022.10.17.07.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 07:41:20 -0700 (PDT) From: Uros Bizjak To: linux-kernel@vger.kernel.org Cc: Uros Bizjak , "Eric W. Biederman" Subject: [PATCH RESEND 2/2] ucount: Use atomic_long_try_cmpxchg in atomic_long_inc_below Date: Mon, 17 Oct 2022 16:40:49 +0200 Message-Id: <20221017144049.3404-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221017144049.3404-1-ubizjak@gmail.com> References: <20221017144049.3404-1-ubizjak@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746946288897527818?= X-GMAIL-MSGID: =?utf-8?q?1746946288897527818?= Use atomic_long_try_cmpxchg instead of atomic_long_cmpxchg (*ptr, old, new) == old in atomic_long_inc_below. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). Also, atomic_long_try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails, enabling further code simplifications. No functional change intended. Signed-off-by: Uros Bizjak Cc: "Eric W. Biederman" Reviewed-by: Alexey Gladkov --- kernel/ucount.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/ucount.c b/kernel/ucount.c index 74f5b4959feb..2c04589a61ff 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -214,16 +214,14 @@ void put_ucounts(struct ucounts *ucounts) static inline bool atomic_long_inc_below(atomic_long_t *v, long u) { - long c, old; - c = atomic_long_read(v); - for (;;) { + long c = atomic_long_read(v); + + do { if (unlikely(c >= u)) return false; - old = atomic_long_cmpxchg(v, c, c+1); - if (likely(old == c)) - return true; - c = old; - } + } while (!atomic_long_try_cmpxchg(v, &c, c+1)); + + return true; } struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid,