Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp464104pxb; Thu, 21 Oct 2021 03:10:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/XLMQm8oKEqRCQIxbuig+OABupVqHaDuOPq9zQUD9JVBPHDv7zEn0wDOny9AyM0Jo0nJH X-Received: by 2002:a17:907:da4:: with SMTP id go36mr6099001ejc.481.1634811023121; Thu, 21 Oct 2021 03:10:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634811023; cv=none; d=google.com; s=arc-20160816; b=Q78W79P1a3bCfdH1RznhzKhaZV7w94q5R8hRfB/4VyhD8p8JCDp2YDocyQkREem1/j bYh4mwc4+xN3iO2Jrr7c2bSekZ3V1raAbEn6No/qZsbmzI/mGBV8VwrFuNR85idPMreb RmexgCoQN/kM/+TIG3Sb4ELBiYe+C6zYQ86R63E7BuloYXdwb5WkJbu4jwQd84vtFTSt yb8LufHoZjvo+oW2Rqpx3H/Ut4IIWByyYlZUehPEw9UjRCf+qidxRa49jFeNDhFmeE/1 SAfbN87bLAOx4omLllH1QM7Osl4968rvXkiaaPkASf+KLb7Lop2OAeLwckMViU+BT1XO TJbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=F1oNJbu4pHa0grSs6d/Ns7GwUCGiFMszmkl6//VgeII=; b=SG08WwtVsh4Zruipng976qbSfcjH6ScStcUuSOmbmI3Tjgl/WBy8bxnyk+rxQ6qTCd dem4tecVsCQaaN2v75kzZtxpw7YOfE9uqZ1Ma0rmV8EASFAFTOTcswaKKF3aw+bjXaDJ YaYEuXRn26xDWxgWxu9Xm8oScnyA9fVwdQO0LH6iUwfDY4h0dBSpRZMLx0GtwOeSYuYV PXofvq8M/Eh9SdHGFnj4dKC3+VXIe4c1qkHq7zb9pu6Mzon5DKQyCRI2G8mT6k2fg+AR kpjLjcX48lxdvVUgqXSmdQ/lvkSOTu7/s8EWsV3bLU3+fsMm1+txViotDOalIwu3px7m jGQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CngsNRHp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si11539082ejc.362.2021.10.21.03.09.59; Thu, 21 Oct 2021 03:10:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CngsNRHp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbhJUKKK (ORCPT + 99 others); Thu, 21 Oct 2021 06:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231371AbhJUKKJ (ORCPT ); Thu, 21 Oct 2021 06:10:09 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAE78C06161C for ; Thu, 21 Oct 2021 03:07:53 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id d13so129001wrf.11 for ; Thu, 21 Oct 2021 03:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=F1oNJbu4pHa0grSs6d/Ns7GwUCGiFMszmkl6//VgeII=; b=CngsNRHpP3xh6N7S6PHF34+fDeYjB5qMaxxKiYNqOUXnACoEzVHxqk0VkPKPnKHdvg hd4xZGhEWkmGTe3+vQq37jqfz+2B9jgU1f/k29IhjSEbTzNY7VEqfRaS4czCiwcWWGQH hXOGa460Fr6GCQuBFg4AjhGLfykL+N3ebKY/x9cgLPB6Ped+HppYo7wg08pEjqSiwrGp rn445z1qcoCtgA/5Sga/yWZjrpnftJ6gvgdJ62aFqCndEfK2v4R7Lp14sVp98mjJLlrY FFldqfowPeNnj06Bs88tiUuL2Aub10yszfkjfJtC0IAk+/dtVc1HWqv5Nos5Cep8XPMq FepQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=F1oNJbu4pHa0grSs6d/Ns7GwUCGiFMszmkl6//VgeII=; b=WX9krUYJ72AMLnOtr+0X2pEfGea3XskSPNJwsPYoMS/OvAUvKApgCCWObUXF0xdGAG 7OvQcMZTp6bZARxsmjsS25KGTDJrpbVlwYdzdoRcJCFXfCuEcl8IOAVeaQ6gLjdDi9Vs 8Y3N0R9prj8KQQRvknGoZ2gnuQ+w0oPxYMBuurPUQ7wPnUNBd2AzsLWwGHsiZFYNi4L3 5CT2CC10xWO+C1fWI/nLTIsCgzL/pCDbw1eVmOuKjLQoZyri/C/HA1PMBYxPtBX4U/Dc PiRW+2EsF7CCK7GPSiiIb81qiSIQn+ITvYhDgKAcjrJR6ecs8nfPkmE+AmFTdj22gJAv Gv5Q== X-Gm-Message-State: AOAM532bovSe7AY+uXmgJykjEy6LhFtUd5aTGDSwm9syS0bwrSElokDW EJeFfiflorGZJm+bZYy6pbW8mg== X-Received: by 2002:adf:a10f:: with SMTP id o15mr6411916wro.286.1634810872098; Thu, 21 Oct 2021 03:07:52 -0700 (PDT) Received: from google.com (216.131.76.34.bc.googleusercontent.com. [34.76.131.216]) by smtp.gmail.com with ESMTPSA id n12sm5422554wri.22.2021.10.21.03.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 03:07:51 -0700 (PDT) Date: Thu, 21 Oct 2021 10:07:47 +0000 From: David Brazdil To: Quentin Perret Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Fuad Tabba , Andrew Walbran , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v2 07/15] KVM: arm64: Introduce kvm_share_hyp() Message-ID: References: <20211019121304.2732332-1-qperret@google.com> <20211019121304.2732332-8-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211019121304.2732332-8-qperret@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Quentin, > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 0019b2309f70..0cc4b295e525 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -299,6 +299,17 @@ static int pkvm_share_hyp(phys_addr_t start, phys_addr_t end) > return 0; > } > > +int kvm_share_hyp(void *from, void *to) > +{ > + if (is_kernel_in_hyp_mode()) > + return 0; > + > + if (kvm_host_owns_hyp_mappings()) > + return create_hyp_mappings(from, to, PAGE_HYP); > + > + return pkvm_share_hyp(kvm_kaddr_to_phys(from), kvm_kaddr_to_phys(to)); We should be careful about vmalloc memory here. kvm_kaddr_to_phys will happily return the physical address but the range is not guaranteed to be physically contiguous. It doesn't look like this series ever shares vmalloc memory, but we should make it harder for users of this function to shoot themselves in the foot. One option would be to turn this into a loop and call pkvm_share_hyp on each physical page. But since the hypervisor has no means of making those pages virtually contigous anyway, probably not the right approach. We could make it possible to share vmalloc buffer that fit into a page and reject others. There we still need to be careful about the upper bound because the way it's written now, 'to' can be treated as exclusive and 'kvm_kaddr_to_phys(to)' would not always return the page after 'kvm_kaddr_to_phys(from)'. -David