Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1162411lql; Tue, 12 Mar 2024 08:57:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVya3P6X3p4Qc3VyV+EjDb/lWvDHzjRLBQoogsqFWtv5Nir+seLS7IN4HHH+HmGr1goAoMfp1EA4iD38tg5M3X46ohumbDo/a0OMVaEQ== X-Google-Smtp-Source: AGHT+IEK0sfKJ8fUwjA3ER/1KU1j/0SHo0eFddyTmfmrkdN0XGeFAe6Kmc1a78xEK991kuPl4oz3 X-Received: by 2002:ad4:50cc:0:b0:690:c43c:b605 with SMTP id e12-20020ad450cc000000b00690c43cb605mr2148240qvq.60.1710259077714; Tue, 12 Mar 2024 08:57:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710259077; cv=pass; d=google.com; s=arc-20160816; b=xFLKT+PZ6wJnpoMcexcyFGLGRFp+peD/K/vOe8pHNI0sxFBF0vT+PiyHnD/4OHm3mq L+9NqKVoGL21Ggf41RkDDWAURbNJxawkNzoZhcGxm6aRTxCe9N0Vpbv/oDfFdLqZr4b7 K/aMDh+IEKQdQ+xuOqbGE88R5OBsgymT8uXTDI1bRccIzBXrCbrYJNSYCAsjdHvtbeLN 3LuySeUvs7RdbLBDofBxMbhTGodX6DYMgN8/FE1ouUkphKLn0h4LUt4KpgeFxsVxFFqH F7tRkwD0SAr5XLih0PVateXSj+r98PP4l6Ee4bckuaUPO+k5+2Yb97c3TeR1WQwlkm6Z k14g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=zlk+aNCie6HXTjVy40lS6l4zYMw7smybyoWxAq6T2Xk=; fh=FfiBONzFIbnVZjWfJyqu/qUS5QPqVgNJV9tLDVB/M9s=; b=bBX6h4kCamSA49KHl3/HvztR9fSRWRr1RV6Id1uMLX/ZS7d1N2LMRKhNirEfbZIaD3 vseP5HV8Fe0jbsYtJqu03+UbvPAVgnpI+pqGFxDvfTGsVJMYluRpv9EaabsYrBkez2RB oBHFv+/tdC1m9HgPHrKtIrj3GAI3ofKr8PNcQfB1IHz6p5r87BrRU+nPUkUmtVwmqwH0 3Sy/l9GJqGMW0kQMHqYepHWhsIoi4IxfJXG/GqnfB5sHQ8R+Da4T90jehpBECyoqSUJv ajfLiEZc/ENujPWt+KauSom/6yMhY2hShlQ0++MruQdIa8xwU7b/uDZVgLro0/KzfoL4 Rcfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JeIpaxEn; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-100482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100482-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w10-20020a05622a190a00b0042eefa46254si7609319qtc.693.2024.03.12.08.57.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 08:57:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JeIpaxEn; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-100482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100482-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 726AE1C209E4 for ; Tue, 12 Mar 2024 15:57:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDFA07D09F; Tue, 12 Mar 2024 15:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JeIpaxEn" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E46E7E585 for ; Tue, 12 Mar 2024 15:56:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710259017; cv=none; b=oSQDRC/Atk8lCLtAsQKHt1Byp5mUopMEKHTTP3Ph2Y6sSXpg6MM2+TaB9De+o7xEKjST6mCWIhUoWhS1YOvvqR2TAgbwwRjH8fNN+vqZ6ntnYs4tH3e98tAwr+IJ0X3bJnN8Rmjs/otnGpj0oRwS1rrG7ndncJOyp+KGV1YefYY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710259017; c=relaxed/simple; bh=PCK/pcEqWjp1zm23P5QkoicRhg3NmpAig6IjG/pvtZ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mJ0BFvfuwJyc8TuEnqMkr0nYsnkxAlB0GWrkpbhjlzJnO8Rv1B9vHPlaGt9A5BbK8lpXUT4S5vP+EOH+v3a3Ajv2uhdY81i8oSLsItWLHXPpdAF8d11pfwQkF8tBg9jhSh0RdcoY7+P3MRscOpiDei1sEaLDHi/RwNFInOnGoPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JeIpaxEn; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a04bc559fso67376567b3.2 for ; Tue, 12 Mar 2024 08:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710259014; x=1710863814; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zlk+aNCie6HXTjVy40lS6l4zYMw7smybyoWxAq6T2Xk=; b=JeIpaxEnTxuGNAd9BKmpepNbk8aZRNTcsneU8+m/pPjWvnWGIzjPjzfFNWfjkdklCN EqVNELviZYrDy8NTaXUk7TQEtCg4ZFSkbh2l+Bh2Na1L7q9/83m/j1Z4LUiMFeA0UM9+ 2FIDsRuth4zElcVtnDJA046uRHKnK4LcKftotVvxnHU+2CRTSsxzZUyMLB/UI2RcA1Z0 adPX4PAfInf3dUGNIMPSGwqLZ5gylvcd5ovLPrdh4zK0Y3XAEozn0h8z01mjOYBnvB8l Km0XotJE6+vEYkp7QVNCivSnrCuXQfI98taCTMgqAHwRzq6gCHrDMUuV+WqHJdaRoVNb 179A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710259014; x=1710863814; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zlk+aNCie6HXTjVy40lS6l4zYMw7smybyoWxAq6T2Xk=; b=sjuBM5uwbVXRHLddpJ7GZUkNDo0dTPZ5T/XPWHMEEN8caGhsxccOd/7rbANWjAd4Ue S62FsXP2sWu44yD07SPJVRJO75ahBHzrk3rsKgqEcuCsZauxTlBT6NZ+8UGS0f4erRbA H1WbiCY+yM8vjp+jwJE6r6C5+I+8V4fB2p5rCtIPXIcb1wf2jZ2gcWkWoHnXiLr5DyIU m0kVHgOO18h2fAgTbzPZy83LB61+LjgSVmnazPo3PvI6477dB+hFCeP8lHpk5CyZCDqJ hlwrkL++5BvxdiwkycOFHppRBzy/jR1v533cEiHw1IY5FUIkH8L3eQpVWsEhymSyI3qk V1yQ== X-Forwarded-Encrypted: i=1; AJvYcCWvBMBV+PRdAR3jv9GH1w0GsMrwc6hBeYOY78LO95bHSB9gGPvZIJm1N/pqyV0/J1w7kjFDPzzfqHARSUkY4t7BagajwHvgRnB4zdhU X-Gm-Message-State: AOJu0Yx6+kTuFzBkDe3d+XKmqkUR9nSj6Cfnpo40vJDvFYgglvRApkmr 1Uw9HXSP6dh+9hIj8B9bilKe+MqJSlF5V2yqKOK4l8g6AZBYMxRGsse4BLRtSDuI+WqPv329CaO hWkChVsdyR05F2de+TA== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:110a:b0:dcc:50ca:e153 with SMTP id o10-20020a056902110a00b00dcc50cae153mr2676138ybu.7.1710259014520; Tue, 12 Mar 2024 08:56:54 -0700 (PDT) Date: Tue, 12 Mar 2024 15:56:41 +0000 In-Reply-To: <20240312155641.4003683-1-yosryahmed@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240312155641.4003683-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240312155641.4003683-3-yosryahmed@google.com> Subject: [PATCH v2 3/3] x86/mm: Cleanup prctl_enable_tagged_addr() nr_bits error checking From: Yosry Ahmed To: x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Kirill A. Shutemov" , Rick Edgecombe , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Content-Type: text/plain; charset="UTF-8" There are two separate checks in prctl_enable_tagged_addr() that nr_bits is in the correct range. The checks are arranged such the correct case is sandwiched between both error cases, which do exactly the same thing. Simplify the if condition and pull the correct case outside with the rest of the success code path. Signed-off-by: Yosry Ahmed Reviewed-by: Kirill A. Shutemov --- arch/x86/kernel/process_64.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 3dd8c1f51e45c..8349431136530 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -783,17 +783,13 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) return -EBUSY; } - if (!nr_bits) { - mmap_write_unlock(mm); - return -EINVAL; - } else if (nr_bits <= LAM_U57_BITS) { - mm->context.lam_cr3_mask = X86_CR3_LAM_U57; - mm->context.untag_mask = ~GENMASK(62, 57); - } else { + if (!nr_bits || nr_bits > LAM_U57_BITS) { mmap_write_unlock(mm); return -EINVAL; } + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; + mm->context.untag_mask = ~GENMASK(62, 57); on_each_cpu_mask(mm_cpumask(mm), enable_lam_func, mm, true); set_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags); -- 2.44.0.278.ge034bb2e1d-goog