Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DB31C636D6 for ; Tue, 31 Jan 2023 03:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbjAaDeW (ORCPT ); Mon, 30 Jan 2023 22:34:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbjAaDeU (ORCPT ); Mon, 30 Jan 2023 22:34:20 -0500 Received: from DM5PR00CU002-vft-obe.outbound.protection.outlook.com (mail-centralusazon11021022.outbound.protection.outlook.com [52.101.62.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3931B2D6E; Mon, 30 Jan 2023 19:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hzNhfaoESEqEC/LgvaikcW1VCkl2TWaNPiOv3jgzlEAqKFiwkJ+ricQ0jX6+mRC6mzp+YVKjVbjTNPs8Ts2mwQ5KouoiL/RZUf2LW8PK1iHtWqkCEKDNon+zM0AIpzrrVPzBvu0hPCZnwRq/hGBUqsLuijZbdDaFGocM3MTcH83wcmr241eBLPGCGZF/4kuE6rX80cQyHcu7C09mIS2EXldqGeRKNVIi7gE/mWn38R/XXX3Wii8EJz016R7thCfTU5Up6F2/X7E/4KrrvF31SyO365Vk0VbP/9Df7ztPmrY1RRobsXcWCEkyqS31PUX3HWl342zSOBf9sR5iYPYbXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=B1TN/soyJxcEfUdF7pZ8jHLorMgnT7s4953SnsHBXLw=; b=YvRo8HWlNy23+L+mKK2HQIqAAdkKr4tpeIBL7UwpDWffNQJm1PyPlBLoa+CHb2lvn5rhF/16Yq8y0HiKyINYLzG/1/FywZoOKPGsyhnDU9oRTu6qx5SUPgJtBf5i2zdl69jVrLZiUgBqL8gBQFWRcQWoTu0U2O4zhyS+ojPWlfryKRcA6zV5/YGqA4m0YuM7VjLhvhg6z695BBk0doP5jrv337kNDBfNrg9Kzl22VuEQwV8j+IhoOYMQR1ShwRFEmJSxVusQNkQ5wVhQ/QbSotEGWUTDaMOU2K9cJoc3aI9yP1OsHKJGcgmEGjA3qEwD472Vs1tT/Q0Ol/7QDuLySg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B1TN/soyJxcEfUdF7pZ8jHLorMgnT7s4953SnsHBXLw=; b=ECT57UyBpU+8uOoSDD+GXCxfubz2EB9ymLZ88avioO2UJTV/HZE140GAxkZGA6wve3SVa47GwWS4U3qTd2JrHJB7Qs0C9K8HNpHQUg1cRIl+PkPTODQEhCoF/Jz4EehgCMB2jrOQNkUVnkDL7nq53bH/2RyxrjAXVi2z0PQP4dE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by DS7PR21MB3150.namprd21.prod.outlook.com (2603:10b6:8:7a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.3; Tue, 31 Jan 2023 03:34:17 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::ef06:2e2c:3620:46a7]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::ef06:2e2c:3620:46a7%7]) with mapi id 15.20.6086.004; Tue, 31 Jan 2023 03:34:17 +0000 From: Michael Kelley To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mikelley@microsoft.com, stable@vger.kernel.org Subject: [PATCH net 1/1] hv_netvsc: Fix missed pagebuf entries in netvsc_dma_map/unmap() Date: Mon, 30 Jan 2023 19:33:06 -0800 Message-Id: <1675135986-254490-1-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MW4PR04CA0055.namprd04.prod.outlook.com (2603:10b6:303:6a::30) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|DS7PR21MB3150:EE_ X-MS-Office365-Filtering-Correlation-Id: 8048df16-08c4-40be-4952-08db033c07cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hj9+g3hDK9DIjRkx95hYfZqpi8e7Uf2cCfatALXy1t/3Ha0ZHW4BWS494/tIqUGVnm6A13n+MzKj6Zk85cWtTv3tVWheFJuSLudEuF7UYBfx3qoiN2xWEUBkl+QOWr11VkQCCwxPE4jwOnILsTycX1bHA3dGhTFGFoqkcqGujAJdLbULHHiGFaaBAVpH1euu3OQtUCHb7tibK2MorUY3QzM7QqIxx5ToWqBjekdeMmWaqzeNwfOK45olOoGLECDECT3tyQieB9yE9IrxKyFTNOj47MYe0D2+7uQBRbEXFtU1KkPY1bTBWQIh1XK+suYrd5/hhh5TYvXybpLzYXBLCa5o3wgl/1sqpUMnED2IRpxwVQRPLHNrKdd7yUtWjpctejSaur9LxWNjwDLGzUJjwu/93Pii0jlSiVrwqVYAzsdzKHBYJUSnDCmmH+iBpOLC2J/hvTqXgKOxmbHA+IYOLHpGcgpasZkc1DQ6rCxxBXpW6EvkhcJ3FtNprLWG0P3unhU+XHI7m3ImXYWSBLgl9BktUMeJ8GD2DfFrAFY5r6EBf/RVcD09JeiCVyJrKthWKSCqmlSqWwCN9HOE3T2dD4KKQe8o8Id4Y86a2o2sN4/R6c/OiT7iXdX/zDmJyzlc45C6Tg/aqSrHmK/2tcHNiylHm1mkfgp0LyF189p8u7d7iU5xaju5ls9LEouEY5+g2HTv7wAu/S7xARM6SPNle2nS7+xI/LzigfZlL66yzX/gjMcwBBAoUpTikPh/O6uLPi2V7xHI9AzEl1mQJBAgwQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199018)(82950400001)(36756003)(38100700002)(38350700002)(82960400001)(86362001)(6512007)(316002)(52116002)(6506007)(186003)(83380400001)(6666004)(478600001)(26005)(10290500003)(66556008)(5660300002)(4326008)(2616005)(41300700001)(921005)(6486002)(66476007)(66946007)(8676002)(2906002)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OW5kR1hvNkFucTcxeGYxRWNqbXBuVHpYZ2pJd3h5bzlzNFhmMkE5Z1pMNXJu?= =?utf-8?B?QmFmRkxnSkZuNWVyOWtrTEt4QjVLRHFPc2lhM09QLzhENC85MlNLb2E4dEE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kenJHMEFQQi8rbGtRanpYd2ZNbmRSdEJWUmFLcGRaNUI3?= =?utf-8?B?YjE4UVZyR29RV3pkMkdPL3hQa3ZFbFJqeHBGbFZYN3BiU3AzaUxJS0s4Y29a?= =?utf-8?B?dzd6R2tzTkpNRE45TzdPU090aUN3dWR5MVVsMjFPUDcydjA5S3ZxV00rR2Jp?= =?utf-8?B?ZWdXWjB5OXN3S3pqOWxKQWFBVjFIT3YwK2pYRUFWVzBDV3Z4L3NMSXpULzhl?= =?utf-8?Q?ZIcss/X06zbvZ3oDLbMBGRfov?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8048df16-08c4-40be-4952-08db033c07cb X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 03:34:16.8459 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JlUXHo4QxcCxrQ83Nq5hJ5n9lodjLUNsQ+H4Y2igZms5YpKH85m/Dij2wEc/Nl6ph7S4h63K4/JP3Y3mZIroYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR21MB3150 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org netvsc_dma_map() and netvsc_dma_unmap() currently check the cp_partial flag and adjust the page_count so that pagebuf entries for the RNDIS portion of the message are skipped when it has already been copied into a send buffer. But this adjustment has already been made by code in netvsc_send(). The duplicate adjustment causes some pagebuf entries to not be mapped. In a normal VM, this doesn't break anything because the mapping doesn’t change the PFN. But in a Confidential VM, dma_map_single() does bounce buffering and provides a different PFN. Failing to do the mapping causes the wrong PFN to be passed to Hyper-V, and various errors ensue. Fix this by removing the duplicate adjustment in netvsc_dma_map() and netvsc_dma_unmap(). Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver") Cc: stable@vger.kernel.org Signed-off-by: Michael Kelley --- drivers/net/hyperv/netvsc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 661bbe6..8acfa40 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -949,9 +949,6 @@ static void netvsc_copy_to_send_buf(struct netvsc_device *net_device, void netvsc_dma_unmap(struct hv_device *hv_dev, struct hv_netvsc_packet *packet) { - u32 page_count = packet->cp_partial ? - packet->page_buf_cnt - packet->rmsg_pgcnt : - packet->page_buf_cnt; int i; if (!hv_is_isolation_supported()) @@ -960,7 +957,7 @@ void netvsc_dma_unmap(struct hv_device *hv_dev, if (!packet->dma_range) return; - for (i = 0; i < page_count; i++) + for (i = 0; i < packet->page_buf_cnt; i++) dma_unmap_single(&hv_dev->device, packet->dma_range[i].dma, packet->dma_range[i].mapping_size, DMA_TO_DEVICE); @@ -990,9 +987,7 @@ static int netvsc_dma_map(struct hv_device *hv_dev, struct hv_netvsc_packet *packet, struct hv_page_buffer *pb) { - u32 page_count = packet->cp_partial ? - packet->page_buf_cnt - packet->rmsg_pgcnt : - packet->page_buf_cnt; + u32 page_count = packet->page_buf_cnt; dma_addr_t dma; int i; -- 1.8.3.1