Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1002123lqb; Wed, 17 Apr 2024 18:29:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/KddRzpM14mxUOx4iv38HPTfVE9w4icm9nOp77sgtqNf2Js3V2vahp9tVj57GvMCmZGyQUlAXh1kowPMOUgx2go7Xkohyh2289eTW2A== X-Google-Smtp-Source: AGHT+IGU1Qthx3H5HLUvtRoSUMqhhgcSHNiZnhJ/QAvePhk4IK+czuMM8aVD1EBfOPczf7A0p1pJ X-Received: by 2002:a05:6a00:2789:b0:6ed:4b2d:a764 with SMTP id bd9-20020a056a00278900b006ed4b2da764mr1251607pfb.11.1713403745460; Wed, 17 Apr 2024 18:29:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713403745; cv=pass; d=google.com; s=arc-20160816; b=qTWYnvTcjmZsXcgRW4HEMV+83fq7cBJdRu92BanbcVRi0GHiDiWYCRBy36s70/3xeF D01uRkZQwlFO3MlfpSsvjmuPHsrrDvR2j25XG5Hi14amJwarlgfDAxlVkJYrcMPZUwTS P3YWvn6ApvJ+5kqAIM+jy67tQDCeX2EwG3ox11cJjCXifk30AvFAaFfD9LAev1QnLagd kgz39NiWAQsF6+2N4G2WN2iSWSI6Axt3s0COdtuoMxwb5z2lIbHgTFQ6vsjyIraT/l8l PiSbqerEF3uMUfPwHOZBtz2WSUK7HritTgcq0i8VLzoAtI6Hfz+yj6sOJZHaYdNR1pBP rt1Q== 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=1IocH4dK3cU7wr7fT/1eXbTtilS5jPEYt4JFcTK0tuc=; fh=RkTkMJkT/ykA6vEXXS0OF9xbZbCrNrjpatlGZRp6m78=; b=LihBh+FlsbqBlY4IAcB47g7RnF/NiHLL7Vh+EUY1Zpv1b9nKSdE8oF5tk7lbU+r8LR 4Avla2MOmiMZsmNcIMBlcc8FN9i1c/QJpk0qbgaGAa3DnQf+EISIkbNDazxmc2dHXO/Y s4DqlDrWO2rKGJnO+r73s/CufMDLyKXPBho3BF3AnIxL0RM7YGgdGEjMrXe03sxPiqLK 8iofWnXpAsyCATLzw9A5BOHKjdKV8aDKmcWZb9TVunT7qtlJdGxu9gswktOmEH7hF48l AEXa3WVDKt6DSaAn9mt08+au5lkFx22PutCY/6CBx8sRF00+Eux1f4fV4EVNAyeRb5/+ Z90w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=A2uvgwyA; 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-149401-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149401-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f25-20020a056a000b1900b006eabed49580si449642pfu.305.2024.04.17.18.29.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 18:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149401-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=A2uvgwyA; 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-149401-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149401-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 12CDC283100 for ; Thu, 18 Apr 2024 01:29:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 345133FBB3; Thu, 18 Apr 2024 01:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A2uvgwyA" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 0F3071E4B3 for ; Thu, 18 Apr 2024 01:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713403724; cv=none; b=jSZghPEB+tsvS0p3DJGSO122GxsmRR1hnsFEWV99Aoxp25jcGvEUck1SFaa4uiENkeVXlxgfsS1xI15uyQv3YWM2yrwkGJdVk+Nc19piWX/drS9SxoB4WerllLqKiCZY/UGblMh3W2dguTcQukGMtGg4nSVPHzi0ZSvFtHF+MOo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713403724; c=relaxed/simple; bh=8J7Bs9WvE9cal/eAWsXQV05lJs/Vf57kuuuUUAVlu/U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jok5BChOCUFmoJTcAtbGbnvPCgJZdr7DHzL2H0+RKuuPj9dMsLV5kU+G6VMJ0IoUSF4RknDqiYsNDA7svp4rZp253swy1+5EbxBQLUA2Z1VsFSYvLtBfop9uwnfaa5ni1z79NBHNp4NCStw4SSAnmy2+xKH1H9SkUexINMKWhFg= 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=A2uvgwyA; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc58cddb50so791783276.0 for ; Wed, 17 Apr 2024 18:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713403722; x=1714008522; 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=1IocH4dK3cU7wr7fT/1eXbTtilS5jPEYt4JFcTK0tuc=; b=A2uvgwyAjh538UhIo8N5EsQpg4E2gSzxOL+JmDyg/c/V+AQM+LCjHEh89+Ju59zAmn xQRcBhduCG4GEFfnqZSbPUz+0i/Q/KaVpVK2BiHTKqKQ8j21JjnOQyHr5zixtcivxMPj fS+9fGgbDnp4ycMh3WgjGbjayFwMKF+3GEA38bH1RDgdn44AFisMIXCgr+S5e5p3R+v5 8Y2Y/LTuPKpb05EXHPG+XyvMuYztGJbmR1y/jw/t3oiKrNbdcjOjscU804PE7+0++wyl hb/M1TNGsBV/KK5+v+NYdyKkWNr0HR6Mrxh773ldK+2cS9m+fmSJrEKaTahbsfc8q1oC IDAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713403722; x=1714008522; 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=1IocH4dK3cU7wr7fT/1eXbTtilS5jPEYt4JFcTK0tuc=; b=CFX7X9RjCXU/WbHDLlGHgYvaDLqQmdXiciolWmXfbc2jOP+duIcvW1y7k27axIAyef Q9yAD/9lVE4L7Vc1BTrYo/pz+EMBkHO/NTyWtcvNjUEVIZx9yJ7gkLvKkmxw0en9FMcB ZRFtEBrnlcGpj8e4b7oc1f7bBQQsVrsvuobINZiWvSn9+VoSFyiWwUhK49P1QjV1JnoQ 5TYtOfxN7p+Gl5rtGzb1bI9FAS2HvCGLJ/MTGEly+1zkfy9UKJnQsw47b7SrdO+xBHar qLL/H3KwRhoYuZeoXhP0e1ANfaR3H30Orf87NLGrPfsoqY/5EfF39HlsYegKIjojDq65 iUzA== X-Forwarded-Encrypted: i=1; AJvYcCVPyYgDZmqQAdS+u5vp90NZBYRtmKR9MfENDKiOGtMq7UQYukIztFvlzLt/eUIjbyiq9aQucVNEC7mhO+BzL7XFK1vLN/kUrdQYbG1o X-Gm-Message-State: AOJu0YyCzjIr0wK5KHWmlvAspCu0rJOOYtJLtiCzHmc5IoH9deLkaUOZ Ty+6p+VU705JCCFh5GwBDUNxRhKBVlqA7QidtaFz3xP9+yp3oKAGm3GCfG2Y80S52Y5K+ZQo71V dFEC5fooZYcc+kWdO9A== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:704:b0:dc6:e1ed:bd1a with SMTP id k4-20020a056902070400b00dc6e1edbd1amr320570ybt.2.1713403721892; Wed, 17 Apr 2024 18:28:41 -0700 (PDT) Date: Thu, 18 Apr 2024 01:28:35 +0000 In-Reply-To: <20240418012835.3360429-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: <20240418012835.3360429-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418012835.3360429-3-yosryahmed@google.com> Subject: [PATCH tip:x86/mm v3 3/3] x86/mm: Cleanup prctl_enable_tagged_addr() nr_bits error checking From: Yosry Ahmed To: x86@kernel.org, Thomas Gleixner , Ingo Molnar Cc: 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 cda2918f88f99..baded5b4907c9 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -831,17 +831,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.683.g7961c838ac-goog