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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3AECC3DA49 for ; Fri, 26 Jul 2024 05:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:In-Reply-To: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YQThcy6xed9kn8EJsXisAuikWbZtGIN23SlH2PNZkcA=; b=uZvHv1gJX5sFg8Jxnd7GymQoE9 wZBp3zebt0LB+3IuauSgfI9E7ZMo0JkYxknwqsn23MF7ZGfVsZZjPInuCxeBPClY6+I3IH+91S+DS AAWyjWu0OCXAxkdBDpgPGniHA3mqwbRXJQmzDXICZlqZVAVDapQ/OksLJvkCdhagkwNJD9hiOmLYu qTzGPAN/0EfMhUYjHHWVEwiwE5BTIOlog/nX3+DuV5WqmONXWGLThDmEf5HtfRmFZRzB0/jtj3Yn0 dWqTijC5N7o7p7KRXipkT2AB392NgsSuu6VNkBDB4YDHOzOYsOO1g9bIhSBSFass6ye90Qg+FI2mm NK3FhI4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXDwD-00000002zTb-2Tmr; Fri, 26 Jul 2024 05:56:21 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXDvo-00000002zN2-0xQj for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 05:55:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721973354; 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: in-reply-to:in-reply-to:references:references; bh=YQThcy6xed9kn8EJsXisAuikWbZtGIN23SlH2PNZkcA=; b=e1Te7lWn/sdLgdUQ1fEX0vdHcLlV0BWzR3f6Uk7ZI/V8Zc6lT1Dh16H7WqZfJ7jQySt8li FlIEY4VQL3DtX+Xh5xtY3JZf3vfrgRp7dArX5E5XEa+FMiQgRq66qYaNkaCV5Isd6CUxDo tK85QSt8yNWc1jMkyFM1XjVJcCy5GCE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-TsPjuvCtMhOxUgYe2tR6RA-1; Fri, 26 Jul 2024 01:55:52 -0400 X-MC-Unique: TsPjuvCtMhOxUgYe2tR6RA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4280291f739so12728015e9.3 for ; Thu, 25 Jul 2024 22:55:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721973351; x=1722578151; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YQThcy6xed9kn8EJsXisAuikWbZtGIN23SlH2PNZkcA=; b=u2YyK7s8iefaq+q5bWqhRiXB3rTPdkek3caWdkdFW+Zin6n33AMFcuAetktctBoYly y7wObOvVzkundvqzLX52R91DHfzW3xkNNj/W6KQ0W+oKFfCJHrzMdIgM26Uz4tTQYUrH 9bXmYT1Z0X8IECIJLZU4lGFKCB8i8LgLNFTUN0xknspe1DmrPTMkss0LAe6y0Jgqx8pH hDmXU4VgZ3CJvwgsM7I10wWNcThCKNblZUm8qLYQnbKNgK3ApR0crP2TUtRFrwbU6dDW y6rObEqzdRmrbcnZn56/0AODcgxEXU/i57dcQwKX/XlmZfSQHqMDqu4Cnn7G4MMshY0n GbUQ== X-Forwarded-Encrypted: i=1; AJvYcCUTz5EGgaf9c8Ygm11uX1XBMJa4Pf3KvrXplSBQ1MK9x7ZGyQyBt++bp0OodOMUl69EoUuJ/RedMZdcPYSHmOfScyc2x2koo/9hWFxLVI691G9aHw4= X-Gm-Message-State: AOJu0YxkEcVvovawciNfeY8I32kZl/XBxP8ZjGBVtLaJWAeEDRD8nBFI SvCv3G2gVxsrQ9AqgMA3K0olmlJVy/c3OIbSxguJTKDaBXePviDCaB2d/PGwtl1uomqIryw/aBH Vib8ZLRTOGBYYZJEJMSXQYO0SN993xyQutKoK6JVkYt00ZLb6ZP5vdADNJ2EQ7MPiujhtmNvX X-Received: by 2002:adf:c08b:0:b0:367:8875:dd4c with SMTP id ffacd0b85a97d-36b31ae2541mr2973084f8f.23.1721973351674; Thu, 25 Jul 2024 22:55:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwUk9Ft0dVUiNjmu7f1QTIXu6q3o+g6VMlVMK1lSks1buGboeYtzHjiLlkzq1mSCBI88a7sA== X-Received: by 2002:adf:c08b:0:b0:367:8875:dd4c with SMTP id ffacd0b85a97d-36b31ae2541mr2973059f8f.23.1721973351027; Thu, 25 Jul 2024 22:55:51 -0700 (PDT) Received: from redhat.com ([2a02:14f:1f7:28ce:f21a:7e1e:6a9:f708]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4280573edbfsm63673365e9.15.2024.07.25.22.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 22:55:50 -0700 (PDT) Date: Fri, 26 Jul 2024 01:55:45 -0400 From: "Michael S. Tsirkin" To: David Woodhouse Cc: Richard Cochran , Peter Hilber , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-rtc@vger.kernel.org, "Ridoux, Julien" , virtio-dev@lists.linux.dev, "Luu, Ryan" , "Chashper, David" , "Mohamed Abuelfotoh, Hazem" , "Christopher S . Hall" , Jason Wang , John Stultz , netdev@vger.kernel.org, Stephen Boyd , Thomas Gleixner , Xuan Zhuo , Marc Zyngier , Mark Rutland , Daniel Lezcano , Alessandro Zummo , Alexandre Belloni , qemu-devel , Simon Horman Subject: Re: [PATCH] ptp: Add vDSO-style vmclock support Message-ID: <20240726012933-mutt-send-email-mst@kernel.org> References: <98813a70f6d3377d3a9d502fd175be97334fcc87.camel@infradead.org> <20240725100351-mutt-send-email-mst@kernel.org> <2a27205bfc61e19355d360f428a98e2338ff68c3.camel@infradead.org> <20240725122603-mutt-send-email-mst@kernel.org> <0959390cad71b451dc19e5f9396d3f4fdb8fd46f.camel@infradead.org> <20240725163843-mutt-send-email-mst@kernel.org> <20240725170328-mutt-send-email-mst@kernel.org> <20240726010511-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 In-Reply-To: <20240726010511-mutt-send-email-mst@kernel.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240725_225556_368066_17EEB601 X-CRM114-Status: GOOD ( 31.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jul 26, 2024 at 01:09:24AM -0400, Michael S. Tsirkin wrote: > On Thu, Jul 25, 2024 at 10:29:18PM +0100, David Woodhouse wrote: > > > > > Then can't we fix it by interrupting all CPUs right after LM? > > > > > > > > > > To me that seems like a cleaner approach - we then compartmentalize > > > > > the ABI issue - kernel has its own ABI against userspace, > > > > > devices have their own ABI against kernel. > > > > > It'd mean we need a way to detect that interrupt was sent, > > > > > maybe yet another counter inside that structure. > > > > > > > > > > WDYT? > > > > > > > > > > By the way the same idea would work for snapshots - > > > > > some people wanted to expose that info to userspace, too. > > > > Those people included me. I wanted to interrupt all the vCPUs, even the > > ones which were in userspace at the moment of migration, and have the > > kernel deal with passing it on to userspace via a different ABI. > > > > It ends up being complex and intricate, and requiring a lot of new > > kernel and userspace support. I gave up on it in the end for snapshots, > > and didn't go there again for this. > > Maybe become you insist on using ACPI? > I see a fairly simple way to do it. For example, with virtio: > > one vq per CPU, with a single outstanding buffer, > callback copies from the buffer into the userspace > visible memory. > > Want me to show you the code? Couldn't resist, so I wrote a bit of this code. Fundamentally, we keep a copy of the hypervisor abi in the device: struct virtclk_info *vci { struct vmclock_abi abi; }; each vq will has its own copy: struct virtqueue_info { struct scatterlist sg[]; struct vmclock_abi abi; } we add it during probe: sg_init_one(vqi->sg, &vqi->abi, sizeof(vqi->abi)); virtqueue_add_inbuf(vq, vqi->sg, 1, &vq->vabi, GFP_ATOMIC); We set the affinity for each vq: for (i = 0; i < num_online_cpus(); i++) virtqueue_set_affinity(vi->vq[i], i); (virtio net does it, and it handles cpu hotplug as well) each vq callback would do: static void vmclock_cb(struct virtqueue *vq) { struct virtclk_info *vci = vq->vdev->priv; struct virtqueue_info *vqi = vq->priv; void *buf; unsigned int len; buf = virtqueue_get_buf(vq, &len); if (!buf) return; BUG_ON(buf != &vq->abi); spin_lock(vci->lock); if (memcmp(&vci->abi, &vqi->abi, sizeof(vqi->abi))) { memcpy(&vci->abi, &vqi->abi, sizeof(vqi->abi)); } /* Update the userspace visible structure now */ ..... /* Re-add the buffer */ virtqueue_add_inbuf(vq, vqi->sg, 1, &vqi->abi, GFP_ATOMIC); spin_unlock(vi->lock); } That's it! Where's the problem here? -- MST