Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2565135ybh; Mon, 5 Aug 2019 03:09:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUjXS5cGm+A780IkRWUXvJFT2bS/TKJmUxpWLOAzXoJll0reqlmjjXKzLoVsmvq6N2VOwA X-Received: by 2002:a63:e10:: with SMTP id d16mr7682893pgl.444.1564999769415; Mon, 05 Aug 2019 03:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564999769; cv=none; d=google.com; s=arc-20160816; b=MPpZQp6qmr1ddBUADIz6/FNiD0gTinxGrttzSc8ca5l8WF1p6kKVIWKtVbbM74rWE0 P4QBkoA1BmJf81HoyGIaRZag28SVKPXzuzUZAvzZqDXiRLvS+iVc1HIMYK61WJW3QDRQ nCL10CiXGZfEM9YgN/x2iYtFW+gZqwDxxNb4W2P0nahl0KpRDc5AiyzKsDvTWl374LVc KkVkMAgAZL854FVd5vJ0QkLQlkLb4fDbI9mtPUJGacYMMiXVsXa8YdsJQvkZFRptbohO BTMdMSkX/BoE79xzEy3I65rFedpUX1YNhGpiwG+Sn9dxwSC1k+LB9lCNZ3+bfRg6GLgz WFXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tSUXfM1GBDtf8d32fnO2t1HSYdqv9TrCrzBesx2Y2r4=; b=QFt3M23njuIVW15V37UmyB+YZmkxkyotVFP0hsFFUKXJBVWmLF83QUU7gOHOhTEqk0 mQDMk9NWdKQy2Gu9Shp7+SOpOOR4bY/ruptQv0Z1KdOTqX5MGLzGn/vKM9yKzQTZ4bgb ZZXU4kxcp7SJhJohmxr9G05outTTYHPYoCgTboyq+kIH+8hFyW0fsUIebFX8FmOSDR6E SPWK/WGMzS1ZbB365JBAIHFr2yCjgv3RIXvEz3HpPQVhDSIImhM5XjuqIMAhM+KTWqws ebNPQUr/ECAHjyAGlfQzGAfY+kIo7TRgcq9QxrI4dWihj9FQUwYXc5mPqQBbzlfLZ9HU 7h3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=WoKh7uXp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si45303041pge.429.2019.08.05.03.09.13; Mon, 05 Aug 2019 03:09:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=WoKh7uXp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728244AbfHEKH0 (ORCPT + 99 others); Mon, 5 Aug 2019 06:07:26 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33046 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728126AbfHEKH0 (ORCPT ); Mon, 5 Aug 2019 06:07:26 -0400 Received: by mail-wm1-f65.google.com with SMTP id h19so6309376wme.0 for ; Mon, 05 Aug 2019 03:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tSUXfM1GBDtf8d32fnO2t1HSYdqv9TrCrzBesx2Y2r4=; b=WoKh7uXp2eFvRFtfyoLMbFxpofblGAbjiJeO/5jm2jytnH6nWtmyKskqrbx75YeQWG V5X7FxP/4rjog38emeYGlmLnkeMOnf/BovPbxPMYUu1xq8C06dJClKqTkSefpyeXPPOR dloeYq+6c+Bto8i7g08vh6qO6tGk3b03w48RVdW9q29kxiHA8HgPPAV4mLyCLFVVpCLz kGN3tWenMO7frIPuKlDOwk2KIxPb19lqRl/xDfpWxOpa4a5PkBCTuNuc7hBrXfCcpfdY xve9XgkFXCe7koQs7AwdgsJb3Ahy04Zm5nfaceawYlnZHHLDT4nMuItmA2DL0whAfhXI ly9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tSUXfM1GBDtf8d32fnO2t1HSYdqv9TrCrzBesx2Y2r4=; b=lq1JfnCkfuLiRcDHXJVi82q8c2GmyQmCW13dbm1QcXQexgyY2iaQplkq+DGm3zTcAN TeAzyqpT348bj/C4ZvzALcCMArUdOue3gxgDTZp1TPFAeE9bLdGCo5z3t3fQjWhrYAk6 vdZpvdlNRG90JbCyP5n6yE6bWcdaua1/FfAg1tRexj8Itist9WfV7YXorOlpsfY+P57L V+Dg3DZ5K6i0FldHBeGphv1aQhBLNL2UOn7P17ot8icVnCfK4SsLgmgHGyH7o3nFYFkd nM4xE6lqzWhKS2QIRqLIRAdy10GI37RGrBBde8kwowGf6NtS43asUFMqVVtbb51wzgtg B0fg== X-Gm-Message-State: APjAAAWixY7VxDNff56oogtM2qY83QZ79DyEy7gIV6eA7EBB6zgydTUe w9gTk82hn9EPZP/nFji62+hxOPoNPBbQatENSKKGGQ== X-Received: by 2002:a1c:cfc5:: with SMTP id f188mr16590824wmg.24.1564999643825; Mon, 05 Aug 2019 03:07:23 -0700 (PDT) MIME-Version: 1.0 References: <20190802074620.115029-1-anup.patel@wdc.com> <20190802074620.115029-12-anup.patel@wdc.com> In-Reply-To: From: Anup Patel Date: Mon, 5 Aug 2019 15:37:12 +0530 Message-ID: Subject: Re: [RFC PATCH v2 11/19] RISC-V: KVM: Implement VMID allocator To: Paolo Bonzini Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Radim K , Daniel Lezcano , Thomas Gleixner , Atish Patra , Alistair Francis , Damien Le Moal , Christoph Hellwig , "kvm@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 2, 2019 at 2:49 PM Paolo Bonzini wrote: > > On 02/08/19 09:48, Anup Patel wrote: > > +struct kvm_vmid { > > + unsigned long vmid_version; > > + unsigned long vmid; > > +}; > > + > > Please document that both fields are written under vmid_lock, and read > outside it. Sure, will add comments in asm/kvm_host.h > > > + /* > > + * On SMP we know no other CPUs can use this CPU's or > > + * each other's VMID after forced exit returns since the > > + * vmid_lock blocks them from re-entry to the guest. > > + */ > > + force_exit_and_guest_tlb_flush(cpu_all_mask); > > Please use kvm_flush_remote_tlbs(kvm) instead. All you need to do to > support it is check for KVM_REQ_TLB_FLUSH and handle it by calling > __kvm_riscv_hfence_gvma_all. Also, since your spinlock is global you > probably should release it around the call to kvm_flush_remote_tlbs. > (Think of an implementation that has a very small number of VMID bits). Sure, I will use kvm_flush_remote_tlbs() here. > > > + if (unlikely(vmid_next == 0)) { > > + WRITE_ONCE(vmid_version, READ_ONCE(vmid_version) + 1); > > + vmid_next = 1; > > + /* > > + * On SMP we know no other CPUs can use this CPU's or > > + * each other's VMID after forced exit returns since the > > + * vmid_lock blocks them from re-entry to the guest. > > + */ > > + force_exit_and_guest_tlb_flush(cpu_all_mask); > > + } > > + > > + vmid->vmid = vmid_next; > > + vmid_next++; > > + vmid_next &= (1 << vmid_bits) - 1; > > + > > + /* Ensure VMID next update is completed */ > > + smp_wmb(); > > This barrier is not necessary. Writes to vmid->vmid need not be ordered > with writes to vmid->vmid_version, because the accesses happen in > completely different places. Yes, your right. There is already a WRITE_ONCE after it. > > (As a rule of thumb, each smp_wmb() should have a matching smp_rmb() > somewhere, and this one doesn't). Sure, thanks for the hint. > > Paolo > > > + WRITE_ONCE(vmid->vmid_version, READ_ONCE(vmid_version)); > > + Regards, Anup