Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1204231lqe; Mon, 8 Apr 2024 01:40:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpnfth8j33gRHX+VRu8FgsQAf5cG9pgVTueswG+k1DFBwqLbt4l1mbgWEiROKEBijiHjQl7BYFD+ZFmXoJEE8FbXY6VWijzMGvf+LIuA== X-Google-Smtp-Source: AGHT+IHZQ7fzy5y71BFrHS6rjx2DOJhIYW+y8j7X47ht7+3mMbL4FC7YNJDkrTHElN+/9ke36PvK X-Received: by 2002:a05:6a20:8405:b0:1a5:bc5d:3c0a with SMTP id c5-20020a056a20840500b001a5bc5d3c0amr11056066pzd.61.1712565618285; Mon, 08 Apr 2024 01:40:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712565618; cv=pass; d=google.com; s=arc-20160816; b=rHyWtJdOb5zvf0c6G5EuAfuuh73yB2sFmfPbH1sIfMx8WLXDw+ebuWoEPAKoouyg1Y bx1p+S3OoHyLPysTELJN4FHWy0j+T9NE9u+FjeFsa0zr+omJLpfH1TdDC+vVxcDPz3uz 8S99CaAGcq48/RMhBPqR8aU6hrkX15gSncV71d0Wt1z52F252XsGD3pnHOWnCbxKh1k5 fgb5Z+435m9F/woSablQk4cb4moVtwwtxg9IvMHNgEIy3sxXw9sWaMA0r3YfuipxTm/E Iy/MztBASLMIBFESR/fPN3Q1/uDvDCJ/pxUjqnzDiylf3FOSmW9F5ysWQcFzsww0KC55 Cqow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=NGE52UNFu7YltYeIy1hEDBg813C3Fl1K3SS0joW2WvQ=; fh=T3QSKeU2bzWOssSBizU7AK+efFFCFjAWDmp2D7epwZk=; b=wfBrg2fd32FnaH3wYJeh353rVEhKgC1/Qz0VSP5uBC+BdKV3EMb2uh4g6Xi2i1/MfC /48pNfXife5bTIGRLrLwGEpuQbq9fUzITKkTWDkiAMwyzPbZ7GlNU/iBKW10QI6ROctZ 0Gcgabcm3a60j/KzBwgHNWlEFRkLIXSLGVDVyhQuzahFD4vlIg7LwCfaxv03rWKUz6Uo NBJTyhZNKrUhB4rakEmDXJyKjNyMc/mbuiluBtRdKpzKFAFkInBKY4XuxbAnJY5euwx+ 18e1rizGtrl8clCOGUVFZKli3vXlAApE4aldVfNbIug0dVeL5LH+Qv34Uab+GsoR5ngP rJxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-135044-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h2-20020a635302000000b005d8c118be4dsi5794501pgb.136.2024.04.08.01.40.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:40:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135044-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-135044-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 BF31D289379 for ; Mon, 8 Apr 2024 08:32:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E32A38F98; Mon, 8 Apr 2024 08:31:44 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C517941A80 for ; Mon, 8 Apr 2024 08:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712565103; cv=none; b=FewfCQTH0dyrnpRmM+EODTDQTOIuUCri5QXHnAmM/7a8Ck6AhCn3wfuyUW85PGbUeb11YPSVfZRybRmDSRR5Y4c/y/v4e60jXzcYFp1/sLMzCX1UB0OrHXnxiW7iaOxaKLewSWqtRgHkrwb97fx/gVr5dMgb4sSW6iqLiTo3Em8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712565103; c=relaxed/simple; bh=cHVXQgWWYQikdi7cXresunZR0HbsRYAMbamgl+6vPTA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AXrylmDhBuzlXzIk18vzdYWKpD7u7JbI1zodkfcMQF8G847A/rnnHXbvOyGfe8s2buMm07l9ipNszJHGsTrejRdlS+wPik7wOaSoP2nWR6yplkDMQfDOCoa46M6XRDdrPRYmGyxdkaJZ9zz5G1GcFJeFuWLBcxocr7EhQJT72cY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6E77B12FC; Mon, 8 Apr 2024 01:32:10 -0700 (PDT) Received: from [10.57.73.169] (unknown [10.57.73.169]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE95E3F766; Mon, 8 Apr 2024 01:31:37 -0700 (PDT) Message-ID: <7766689e-a473-475d-8bf6-c1d7435881c9@arm.com> Date: Mon, 8 Apr 2024 09:31:36 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/3] arm64: tlb: Improve __TLBI_VADDR_RANGE() Content-Language: en-GB To: Gavin Shan , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, maz@kernel.org, oliver.upton@linux.dev, apopple@nvidia.com, rananta@google.com, mark.rutland@arm.com, v-songbaohua@oppo.com, yangyicong@hisilicon.com, shahuang@redhat.com, yihyu@redhat.com, shan.gavin@gmail.com References: <20240405035852.1532010-1-gshan@redhat.com> <20240405035852.1532010-3-gshan@redhat.com> From: Ryan Roberts In-Reply-To: <20240405035852.1532010-3-gshan@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 05/04/2024 04:58, Gavin Shan wrote: > The macro returns the operand of TLBI RANGE instruction. A mask needs > to be applied to each individual field upon producing the operand, to > avoid the adjacent fields can interfere with each other when invalid > arguments have been provided. The code looks more tidy at least with > a mask and FIELD_PREP(). > > Suggested-by: Marc Zyngier > Signed-off-by: Gavin Shan LGTM! Reviewed-by: Ryan Roberts > --- > arch/arm64/include/asm/tlbflush.h | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) > > diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h > index a75de2665d84..243d71f7bc1f 100644 > --- a/arch/arm64/include/asm/tlbflush.h > +++ b/arch/arm64/include/asm/tlbflush.h > @@ -142,17 +142,24 @@ static inline unsigned long get_trans_granule(void) > * EL1, Inner Shareable". > * > */ > -#define __TLBI_VADDR_RANGE(baddr, asid, scale, num, ttl) \ > - ({ \ > - unsigned long __ta = (baddr); \ > - unsigned long __ttl = (ttl >= 1 && ttl <= 3) ? ttl : 0; \ > - __ta &= GENMASK_ULL(36, 0); \ > - __ta |= __ttl << 37; \ > - __ta |= (unsigned long)(num) << 39; \ > - __ta |= (unsigned long)(scale) << 44; \ > - __ta |= get_trans_granule() << 46; \ > - __ta |= (unsigned long)(asid) << 48; \ > - __ta; \ > +#define TLBIR_ASID_MASK GENMASK_ULL(63, 48) > +#define TLBIR_TG_MASK GENMASK_ULL(47, 46) > +#define TLBIR_SCALE_MASK GENMASK_ULL(45, 44) > +#define TLBIR_NUM_MASK GENMASK_ULL(43, 39) > +#define TLBIR_TTL_MASK GENMASK_ULL(38, 37) > +#define TLBIR_BADDR_MASK GENMASK_ULL(36, 0) > + > +#define __TLBI_VADDR_RANGE(baddr, asid, scale, num, ttl) \ > + ({ \ > + unsigned long __ta = 0; \ > + unsigned long __ttl = (ttl >= 1 && ttl <= 3) ? ttl : 0; \ > + __ta |= FIELD_PREP(TLBIR_BADDR_MASK, baddr); \ > + __ta |= FIELD_PREP(TLBIR_TTL_MASK, __ttl); \ > + __ta |= FIELD_PREP(TLBIR_NUM_MASK, num); \ > + __ta |= FIELD_PREP(TLBIR_SCALE_MASK, scale); \ > + __ta |= FIELD_PREP(TLBIR_TG_MASK, get_trans_granule()); \ > + __ta |= FIELD_PREP(TLBIR_ASID_MASK, asid); \ > + __ta; \ > }) > > /* These macros are used by the TLBI RANGE feature. */