Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2406383imm; Thu, 19 Jul 2018 20:35:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfMdvmkSwNYS9L0mSbDlccSj7nRTDV0yRLlZOS+wVVRjqbSW7rRuIhPegW1CAbaRtXajxt6 X-Received: by 2002:a62:3f44:: with SMTP id m65-v6mr442633pfa.98.1532057755066; Thu, 19 Jul 2018 20:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532057755; cv=none; d=google.com; s=arc-20160816; b=uNOI97NqnaLyTwGvusqeidPm9sMtOOy39aIw7ePpZJg5bqVuhaITEoy5sEY2z7hWrK 3KsHWSIjAokeqVa1gpWUuJn8pWdA2aBf8uId3Ih0XBWLfthSAUe2fXBG3tPLBMkoIsI9 Sq9AOHUgyzzd4aR4xC3Fq3IqCQL9SIBekNm4kRWqnuDXjX2DS3e5Gh5LKvA5UYMJlr67 +1mW+adAF4wCQpaOp8UjHibAdl3A5uG6D7mvMLEVzHUuYyy5w6gHJz9XSgwc8H6yEt+j TQqWudQNeNOECdJrHlknhZo1NNUpFBHH81KST6+p4OggdX9/NU+UgIKaVmkhcLGpeTCB au/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=hBiUyMzEt935O9OT+YKPhS4xVJTMRpPhveQnYjrUU5s=; b=jVRbBW5vGxgip2+M2bivRMu8OpM/QUbMQuSJZOrFKrO+ytpkPd3wRWcIcpaHFlbU3y /eEcV0GSRztnRvHondH7cC6po4wghe/0O49IwqXtOWCBSqUdy91rvsUlMCTzPW3S91AL 6mQxfVK9JFctfKHPUTkmVkJAdWVBJcdexD8p4DmoCro+F0uDafJaHnb33ZVVoJDTJgFk LkA1ni2fT8w2CHzdY6805wUo9NyNQYTlvdNw+VMwgC1nEOnQkAaEUP/KOUbbmTh5wK1z DMREUR/nRnJKtMzJvgTP3qz+zX3ah0slm1o8PLlOUwOVaTOrQC43C1az9xT158Lc0j8e BNHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AzS97atw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i184-v6si878113pfg.250.2018.07.19.20.35.40; Thu, 19 Jul 2018 20:35:55 -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=@gmail.com header.s=20161025 header.b=AzS97atw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727011AbeGTEVL (ORCPT + 99 others); Fri, 20 Jul 2018 00:21:11 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:39643 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbeGTEVL (ORCPT ); Fri, 20 Jul 2018 00:21:11 -0400 Received: by mail-oi0-f67.google.com with SMTP id d189-v6so18893834oib.6; Thu, 19 Jul 2018 20:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=hBiUyMzEt935O9OT+YKPhS4xVJTMRpPhveQnYjrUU5s=; b=AzS97atwCVCHQjknQ59FZYZW6JkeG/chfa9cum3303HNw3oIjAVyv3CQ9idHEvX9gW SWjhosof0Ehc+x3DVLydBpg4vH/j1WizzAOC+O3EXtnCEhxHFjdC+zgkmUGIsW79463A DVSGcJk5WDnvHZgCRo4uy3TjUpIp8114IkJBGkVggONAxJv/gxv5H2+rz58eqFBDDZN7 gY4zs4A+znN53wwDUZjqOGlt5RdANPt7w3P0e6J0x3GNF+kCO5bs5KJpOox5n+2rD96C vvL8SFWp8ZIfYn1Qm/SvUWoqSPmgZj4qXv4tSYhrc2Zv3HZngKB4DcYoT+6b7/ium3x1 07TQ== 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:content-transfer-encoding; bh=hBiUyMzEt935O9OT+YKPhS4xVJTMRpPhveQnYjrUU5s=; b=ovQ/012xyZEBiXBokZAbYXUUi9tewCaJKyTXJ4P41Ypx3lNkXMhTQFcvv/xBVtdOez 34n26Hgj1muHz07IeD9vVDEJ5nKXR+0qapIufdijm1nWMi7qIGHRW787fW/8WkvekeHN q/Q046uggxAxdpWJrtnb7s3dVT18SlFViQdrM7WUQtUcg+3z/ndG98h0L1PUBvoMrtzm fBGYuA0jS7cGhNVz3HRJsYAc4H9FgN2Sdkjs/xFAY+XjjTEmt1W95gkcnn802UFn8AYv bhoqiXIe1t+2V1dSD5/qbFUUESREn5v4CUQOzBlJpVZ8bfjay3qOhl7i3lEtYqCQUQx2 GBIw== X-Gm-Message-State: AOUpUlHhcMyUxMgIK6ggQPOfgH+IA4o/LMnloQbS5FJP/ed1LDOtNRu1 Woa86pkSFTFMChXbtPo2qBMqcJxk/+mI65fgysE= X-Received: by 2002:aca:b585:: with SMTP id e127-v6mr358075oif.119.1532057703352; Thu, 19 Jul 2018 20:35:03 -0700 (PDT) MIME-Version: 1.0 References: <1530598891-21370-1-git-send-email-wanpengli@tencent.com> <1530598891-21370-3-git-send-email-wanpengli@tencent.com> <20180719162826.GB11749@flask> <1357a0b5-0cd8-8cb5-6c61-c9662219bed0@redhat.com> In-Reply-To: <1357a0b5-0cd8-8cb5-6c61-c9662219bed0@redhat.com> From: Wanpeng Li Date: Fri, 20 Jul 2018 11:35:07 +0800 Message-ID: Subject: Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest To: Paolo Bonzini Cc: Radim Krcmar , LKML , kvm , Vitaly Kuznetsov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini wrote: > > On 19/07/2018 18:28, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > >> + > >> + kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, = vector); > > and > > > > kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vec= tor); > > > > Still, the main problem is that we can only address 128 APICs. > > > > A simple improvement would reuse the vector field (as we need only 8 > > bits) and put a 'offset' in the rest. The offset would say which > > cluster of 128 are we addressing. 24 bits of offset results in 2^31 > > total addressable CPUs (we probably should even use that many bits). > > The downside of this is that we can only address 128 at a time. > > > > It's basically the same as x2apic cluster mode, only with 128 cluster > > size instead of 16, so the code should be a straightforward port. > > And because x2apic code doesn't seem to use any division by the cluster > > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and > > make the cluster size 192. :) > > I did suggest an offset earlier in the discussion. > > The main problem is that consecutive CPU ids do not map to consecutive > APIC ids. But still, we could do an hypercall whenever the total range > exceeds 64. Something like > > u64 ipi_bitmap =3D 0; > for_each_cpu(cpu, mask) > if (!ipi_bitmap) { > min =3D max =3D cpu; > } else if (cpu < min && max - cpu < 64) { > ipi_bitmap <<=3D min - cpu; > min =3D cpu; > } else if (id < min + 64) { > max =3D cpu < max ? max : cpu; > } else { > /* ... send hypercall... */ > min =3D max =3D cpu; > ipi_bitmap =3D 0; > } > __set_bit(ipi_bitmap, cpu - min); > } > if (ipi_bitmap) { > /* ... send hypercall... */ > } > > We could keep the cluster size of 128, but it would be more complicated > to do the left shift in the first "else if". If the limit is 64, you > can keep the two arguments in the hypercall, and just pass 0 as the > "high" bitmap on 64-bit kernels. Cool, i will try the offset method in next version. Thanks for your review, Paolo! :) Regards, Wanpeng Li