From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E629C4320E for ; Thu, 2 Sep 2021 13:36:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B1F560525 for ; Thu, 2 Sep 2021 13:36:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345180AbhIBNhF (ORCPT ); Thu, 2 Sep 2021 09:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234350AbhIBNhC (ORCPT ); Thu, 2 Sep 2021 09:37:02 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01BABC061575; Thu, 2 Sep 2021 06:36:04 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id fs6so1362537pjb.4; Thu, 02 Sep 2021 06:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3ii/guKHn4LpF03RfgLBF/j9oSVP4qa5E4ECxRbe8hE=; b=SQm9Nj4ysgjXU+46HOkYd8Q+/51pgR0klYtCW81HunVSPpNqA+7K6ET2S66TXtFo5V dUkSrrWmLdz9TgWh/ywwICTIxatEgDnyhnQs5/AiLJGp5rcv9KvBnwyhADMsOmMIBDEE nzezmmPn+wpRYYcADoD+nWE8McbCwOsGC+BH28wlQdSj65Vv6aiEEaIhoTM3yHym8m8M uJ7pUAhfdy9O2NQ1ZT90Jct19BmiUoi4Lm8Un1aHkNzAhPQO1ioDu9bRjpEUheed7PwG NaFORAtAC9wGX5zQ/JUlDZFdP09/92z+FxuN3oVRGo0d4SLQnwGPjmGI7zp0OcLmFhww rJ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3ii/guKHn4LpF03RfgLBF/j9oSVP4qa5E4ECxRbe8hE=; b=S8iLwBaKjMJjvFqHVrJiTu1Te2YUqo61fFy2qrYxfDZkS/iz8tu70RLW8T/5zPTT3d qX9Z5+Jo31JeSaZTX4Uj+/7++yFUF0u7BwflXP/QrWfRwO5TAI+ZP8o+JzY0c39/rGSh c7KOubGwRMZMToAksbE8J97uVC/97DYZlXcqW0x1GbD18v/BhNBlbIYDq47tCnBllV9T IlRVkIVK7GSOLRK/iGX2eolA6nv0OKaKPo3wjjo8O7OdyDya4k1GvkayveXeMBE6W766 EMTO761rqeMeFyiVcHyQtxUtGtz0cSvYFieXiaMlSibxUkc7AtbuyeiOi+sw7TlgFK3n bl9g== X-Gm-Message-State: AOAM532Mceaf2+M9los7Y0ABX9H996UP0buL98G6fRDNpL0ARvdv2Nq/ 06VcDWZeO/b1wgexJvMxZRk= X-Google-Smtp-Source: ABdhPJxb2ycIjPIdhzbaYk0Qkm84LE40W+f5tgz7hUwm6cNYqkebQcMmosgs/I437B2b32yx0P3oCw== X-Received: by 2002:a17:902:c408:b0:138:e3df:e999 with SMTP id k8-20020a170902c40800b00138e3dfe999mr2981076plk.30.1630589763493; Thu, 02 Sep 2021 06:36:03 -0700 (PDT) Received: from ?IPv6:2404:f801:0:5:8000::50b? ([2404:f801:9000:1a:efea::50b]) by smtp.gmail.com with ESMTPSA id a10sm2447079pja.14.2021.09.02.06.35.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Sep 2021 06:36:03 -0700 (PDT) Subject: Re: [PATCH V4 08/13] hyperv/vmbus: Initialize VMbus ring buffer for Isolation VM To: Michael Kelley , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "wei.liu@kernel.org" , Dexuan Cui , "catalin.marinas@arm.com" , "will@kernel.org" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "x86@kernel.org" , "hpa@zytor.com" , "dave.hansen@linux.intel.com" , "luto@kernel.org" , "peterz@infradead.org" , "konrad.wilk@oracle.com" , "boris.ostrovsky@oracle.com" , "jgross@suse.com" , "sstabellini@kernel.org" , "joro@8bytes.org" , "davem@davemloft.net" , "kuba@kernel.org" , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" , "gregkh@linuxfoundation.org" , "arnd@arndb.de" , "hch@lst.de" , "m.szyprowski@samsung.com" , "robin.murphy@arm.com" , "brijesh.singh@amd.com" , "thomas.lendacky@amd.com" , Tianyu Lan , "pgonda@google.com" , "martin.b.radev@gmail.com" , "akpm@linux-foundation.org" , "kirill.shutemov@linux.intel.com" , "rppt@kernel.org" , "hannes@cmpxchg.org" , "aneesh.kumar@linux.ibm.com" , "krish.sadhukhan@oracle.com" , "saravanand@fb.com" , "linux-arm-kernel@lists.infradead.org" , "xen-devel@lists.xenproject.org" , "rientjes@google.com" , "ardb@kernel.org" Cc: "iommu@lists.linux-foundation.org" , "linux-arch@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-scsi@vger.kernel.org" , "netdev@vger.kernel.org" , vkuznets , "parri.andrea@gmail.com" , "dave.hansen@intel.com" References: <20210827172114.414281-1-ltykernel@gmail.com> <20210827172114.414281-9-ltykernel@gmail.com> From: Tianyu Lan Message-ID: Date: Thu, 2 Sep 2021 21:35:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/2/2021 8:23 AM, Michael Kelley wrote: >> + } else { >> + pages_wraparound = kcalloc(page_cnt * 2 - 1, >> + sizeof(struct page *), >> + GFP_KERNEL); >> + >> + pages_wraparound[0] = pages; >> + for (i = 0; i < 2 * (page_cnt - 1); i++) >> + pages_wraparound[i + 1] = >> + &pages[i % (page_cnt - 1) + 1]; >> + >> + ring_info->ring_buffer = (struct hv_ring_buffer *) >> + vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, >> + PAGE_KERNEL); >> + >> + kfree(pages_wraparound); >> + if (!ring_info->ring_buffer) >> + return -ENOMEM; >> + } > With this patch, the code is a big "if" statement with two halves -- one > when SNP isolation is in effect, and the other when not. The SNP isolation > case does the work using PFNs with the shared_gpa_boundary added, > while the other case does the same work but using struct page. Perhaps > I'm missing something, but can both halves be combined and always > do the work using PFNs? The only difference is whether to add the > shared_gpa_boundary, and whether to zero the memory when done. > So get the starting PFN, then have an "if" statement for whether to > add the shared_gpa_boundary. Then everything else is the same. > At the end, use an "if" statement to decide whether to zero the > memory. It would really be better to have the logic in this algorithm > coded only once. > Hi Michael: I have tried this before. But vmap_pfn() only works for those pfns out of normal memory. Please see vmap_pfn_apply() for detail and return error when the PFN is valid.