From nobody Sat Nov 23 01:56:43 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A00B71EEE0 for ; Mon, 18 Nov 2024 01:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731892123; cv=none; b=jxJ6OTx2mKm9nIEpQ3VQycE3HVohNhpNtEfIVOr0rFI1aL6sGkRRNZhSS07W95BUXcZkYPEmCGBzn5E2Ale3ta+Ak7o59E40hSscLbkc2ZxWa1zBwSh78DvaH8ZWhL+36YdMBgyA/anAqQD3mAJOD7YeH+IMxGlqKuFdsw6o5aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731892123; c=relaxed/simple; bh=op7OKdRde168TntIHn22QHMGmYZuySYmn6eZrPmYniM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=NujHHEnk6Y+ehcFylyG4GT5U7tZFTgHR/OAjU3ZUzA6l0kQCSdW+Ig67hHb9BEKmyVL0hYcZlPMgxcA6sA3VD768kUGrB9MCiJ2irJVpDR+SREKLfLO+mgVXJOgTX9chJBn2cIiT02O4sXK/7sW+Qr6Va3N4u3w+vKWkoOUbWgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NWezKf1l; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NWezKf1l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731892119; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zni2P8RXs1NIgqnGj1dvk2TFcixosLxM92vTQmUu8zE=; b=NWezKf1lbPzRAj1GRKDq6XDeqSpD457wVwD6kW3T2ycz5/77TU3qcffELMxhQgweBw24iQ tAiAr1WsEz4/KN5JlNRMwIzcwVNNUiS+PS5QIKviowRdGAv/vueTckIFmdVlczPyZePOy0 PeEQVvUvQQplIbsCXzUGSX3LOTJLZRY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-SfR6VTcJOayfGfqzwCF1gQ-1; Sun, 17 Nov 2024 20:08:34 -0500 X-MC-Unique: SfR6VTcJOayfGfqzwCF1gQ-1 X-Mimecast-MFC-AGG-ID: SfR6VTcJOayfGfqzwCF1gQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E6CD71955F37; Mon, 18 Nov 2024 01:08:32 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.113.10]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2794A300019E; Mon, 18 Nov 2024 01:08:26 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org, mingo@kernel.org, bp@alien8.de, thomas.lendacky@amd.com Cc: x86@kernel.org, Baoquan He Subject: [PATCH v2 1/2] x86/ioremap: introduce helper to implement xxx_is_setup_data() Date: Mon, 18 Nov 2024 09:08:18 +0800 Message-ID: <20241118010819.46602-2-bhe@redhat.com> In-Reply-To: <20241118010819.46602-1-bhe@redhat.com> References: <20241118010819.46602-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Functions memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except of the different memremap/unmap invocations. So add helper __memremap_is_setup_data() to extract the common part, parameter 'early' is used to decide what kind of memremap/unmap APIs are called. This simplifies codes a lot by removing the duplicated codes, and also removes the similar code comment above them. And '__ref' is added to __memremap_is_setup_data() to suppress below section mismatch warning: ARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setu= p_data+0x5f (section: .text) -> early_memunmap (section: .init.text) Signed-off-by: Baoquan He --- arch/x86/mm/ioremap.c | 108 +++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 70 deletions(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 8d29163568a7..68d78e2b1203 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -628,12 +628,13 @@ static bool memremap_is_efi_data(resource_size_t phys= _addr, return false; } =20 +#define SD_SIZE sizeof(struct setup_data) /* * Examine the physical address to determine if it is boot data by checking * it against the boot params setup_data chain. */ -static bool memremap_is_setup_data(resource_size_t phys_addr, - unsigned long size) +static bool __ref __memremap_is_setup_data(resource_size_t phys_addr, + bool early) { struct setup_indirect *indirect; struct setup_data *data; @@ -641,31 +642,45 @@ static bool memremap_is_setup_data(resource_size_t ph= ys_addr, =20 paddr =3D boot_params.hdr.setup_data; while (paddr) { - unsigned int len; + unsigned int len, size; =20 if (phys_addr =3D=3D paddr) return true; =20 - data =3D memremap(paddr, sizeof(*data), - MEMREMAP_WB | MEMREMAP_DEC); + if (early) + data =3D early_memremap_decrypted(paddr, SD_SIZE); + else + data =3D memremap(paddr, SD_SIZE, + MEMREMAP_WB | MEMREMAP_DEC); if (!data) { pr_warn("failed to memremap setup_data entry\n"); return false; } =20 + size =3D SD_SIZE; + paddr_next =3D data->next; len =3D data->len; =20 if ((phys_addr > paddr) && - (phys_addr < (paddr + sizeof(struct setup_data) + len))) { - memunmap(data); + (phys_addr < (paddr + SD_SIZE + len))) { + if (early) + early_memunmap(data, SD_SIZE); + else + memunmap(data); return true; } =20 if (data->type =3D=3D SETUP_INDIRECT) { - memunmap(data); - data =3D memremap(paddr, sizeof(*data) + len, - MEMREMAP_WB | MEMREMAP_DEC); + size +=3D len; + if (early) { + early_memunmap(data, SD_SIZE); + data =3D early_memremap_decrypted(paddr, size); + } else { + memunmap(data); + data =3D memremap(paddr, size, + MEMREMAP_WB | MEMREMAP_DEC); + } if (!data) { pr_warn("failed to memremap indirect setup_data\n"); return false; @@ -679,7 +694,10 @@ static bool memremap_is_setup_data(resource_size_t phy= s_addr, } } =20 - memunmap(data); + if (early) + early_memunmap(data, size); + else + memunmap(data); =20 if ((phys_addr > paddr) && (phys_addr < (paddr + len))) return true; @@ -689,68 +707,18 @@ static bool memremap_is_setup_data(resource_size_t ph= ys_addr, =20 return false; } +#undef SD_SIZE =20 -/* - * Examine the physical address to determine if it is boot data by checking - * it against the boot params setup_data chain (early boot version). - */ -static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, - unsigned long size) +static bool memremap_is_setup_data(resource_size_t phys_addr, + unsigned long size) { - struct setup_indirect *indirect; - struct setup_data *data; - u64 paddr, paddr_next; - - paddr =3D boot_params.hdr.setup_data; - while (paddr) { - unsigned int len, size; - - if (phys_addr =3D=3D paddr) - return true; - - data =3D early_memremap_decrypted(paddr, sizeof(*data)); - if (!data) { - pr_warn("failed to early memremap setup_data entry\n"); - return false; - } - - size =3D sizeof(*data); - - paddr_next =3D data->next; - len =3D data->len; - - if ((phys_addr > paddr) && - (phys_addr < (paddr + sizeof(struct setup_data) + len))) { - early_memunmap(data, sizeof(*data)); - return true; - } - - if (data->type =3D=3D SETUP_INDIRECT) { - size +=3D len; - early_memunmap(data, sizeof(*data)); - data =3D early_memremap_decrypted(paddr, size); - if (!data) { - pr_warn("failed to early memremap indirect setup_data\n"); - return false; - } - - indirect =3D (struct setup_indirect *)data->data; - - if (indirect->type !=3D SETUP_INDIRECT) { - paddr =3D indirect->addr; - len =3D indirect->len; - } - } - - early_memunmap(data, size); - - if ((phys_addr > paddr) && (phys_addr < (paddr + len))) - return true; - - paddr =3D paddr_next; - } + return __memremap_is_setup_data(phys_addr, false); +} =20 - return false; +static bool early_memremap_is_setup_data(resource_size_t phys_addr, + unsigned long size) +{ + return __memremap_is_setup_data(phys_addr, true); } =20 /* --=20 2.41.0 From nobody Sat Nov 23 01:56:43 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 121EE17BA2 for ; Mon, 18 Nov 2024 01:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731892125; cv=none; b=JI4k+s2NaemH9qpH2/sjeYPTyhjZaIFBx5G4Plmxkuv4WMozPxyW0lx2M1qrUOY9fjD8v7MasPovwnv+kAUelPNdLEVodgBaeRDflv0uSCLJ8wh9OfadNRKE680lnoibMJfU77kbkXFJuIscvN6KHxDfgaI7fU78k4zQ0820GMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731892125; c=relaxed/simple; bh=PoW4nNs0VhdihucMJl2U7xHf/YDFPe+84CxzxjrHMkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=UZBQaX1WnKw+LVXzrE9LTMKlat+HGG3hEXlGHpSmwSYr+FbST+ZrAnjzmkSa0JiswJP8HIHbooYO+Ugki1/buhnCuidotRRTESPcGWF1SpbsMH0Ja7i9izem3QJEfPPSPlgsT3m0CP9SF/0O2mLmfxyHgwF+QhVMTMZcCnSzmKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Sl6ceI7G; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Sl6ceI7G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731892123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojwUhaZ6QLal1kPk+jXM8dL/jirGYZcv159NaGpG9I0=; b=Sl6ceI7GQvI9Hk2pitvrJp0Id47OzX7veINR7KsAnIRDtW7sPo18W06h2GFSkKyeT52EXo qmBbfBxUd7ZEo+zyiIfvEpZGtG23RF1O1+XIAfP63cxNuITbB4+gTPWFWh3rZyyFNFus8y ET0NayBiIAwNSzk77miPclY5y8iPE0U= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-xP2-gD_rPEyjdu5w_AlxeA-1; Sun, 17 Nov 2024 20:08:39 -0500 X-MC-Unique: xP2-gD_rPEyjdu5w_AlxeA-1 X-Mimecast-MFC-AGG-ID: xP2-gD_rPEyjdu5w_AlxeA Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 072FA19560AD; Mon, 18 Nov 2024 01:08:38 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.113.10]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C3968300019E; Mon, 18 Nov 2024 01:08:33 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org, mingo@kernel.org, bp@alien8.de, thomas.lendacky@amd.com Cc: x86@kernel.org, Baoquan He Subject: [PATCH v2 2/2] x86/mm: clean up unused parameters of functions Date: Mon, 18 Nov 2024 09:08:19 +0800 Message-ID: <20241118010819.46602-3-bhe@redhat.com> In-Reply-To: <20241118010819.46602-1-bhe@redhat.com> References: <20241118010819.46602-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" For functions memremap_is_efi_data(), memremap_is_setup_data and early_memremap_is_setup_data(), their parameter 'size' is not used and sometime cause confusion. Remove it now. Signed-off-by: Baoquan He --- arch/x86/mm/ioremap.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 68d78e2b1203..569a62b047a0 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -593,8 +593,7 @@ static bool memremap_should_map_decrypted(resource_size= _t phys_addr, * Examine the physical address to determine if it is EFI data. Check * it against the boot params structure and EFI tables and memory types. */ -static bool memremap_is_efi_data(resource_size_t phys_addr, - unsigned long size) +static bool memremap_is_efi_data(resource_size_t phys_addr) { u64 paddr; =20 @@ -709,14 +708,12 @@ static bool __ref __memremap_is_setup_data(resource_s= ize_t phys_addr, } #undef SD_SIZE =20 -static bool memremap_is_setup_data(resource_size_t phys_addr, - unsigned long size) +static bool memremap_is_setup_data(resource_size_t phys_addr) { return __memremap_is_setup_data(phys_addr, false); } =20 -static bool early_memremap_is_setup_data(resource_size_t phys_addr, - unsigned long size) +static bool early_memremap_is_setup_data(resource_size_t phys_addr) { return __memremap_is_setup_data(phys_addr, true); } @@ -739,8 +736,8 @@ bool arch_memremap_can_ram_remap(resource_size_t phys_a= ddr, unsigned long size, return false; =20 if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) { - if (memremap_is_setup_data(phys_addr, size) || - memremap_is_efi_data(phys_addr, size)) + if (memremap_is_setup_data(phys_addr) || + memremap_is_efi_data(phys_addr)) return false; } =20 @@ -765,8 +762,8 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_s= ize_t phys_addr, encrypted_prot =3D true; =20 if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) { - if (early_memremap_is_setup_data(phys_addr, size) || - memremap_is_efi_data(phys_addr, size)) + if (early_memremap_is_setup_data(phys_addr) || + memremap_is_efi_data(phys_addr)) encrypted_prot =3D false; } =20 --=20 2.41.0