From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C596E3CB544 for ; Mon, 17 Aug 2026 09:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786957213; cv=none; b=BmIL5dqtvx2D3AU4mca7OQc+OZtYDHYk/CSDP6D+OMZQtDNGutMOznc33S8xF0oHPOL/32ik8vHMso+TiKGql9TZatv0vwyQKwvK00EGNAjJ6qxgOZYdc0W8k/VtJ5N2mBSHogwzr2vY++txsIJTL/SGYjFvkue6Zrs4nDvqM0U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786957213; c=relaxed/simple; bh=e+IPplwFXzoFzsk0DFknbE3Fku2750DCqHORU9LUwdw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lEVBSzPuT+bSeCZuP1BmhtTxBYfEJz0r44fJnqIntr2RGy+vZ+hQVxHLTGSrs4k8QdlWQvC7nZdra5hoJDMADTQ025jlKt07ZuSyy6DnHln/YOnRGu22W1RHK6E94En3rs9r4pJuqcfVEDqtNLbRHC6lf7r/70IPYtvUyKC0dUU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Zjql0Si5; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=UI508pk0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Zjql0Si5"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="UI508pk0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786957210; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3OSbmtJaxuAXKm9wxovJJHMJ29/ztwYERcUJ/tlgLm4=; b=Zjql0Si5/4zEBtBrvAfgQxo2UgFEIj5KhVEMGV4jKGDni/NHXz6pAxeYyr0NG2Tnqk1X0o KdYtQiwGqgL9h2I7UzUK8PGxo6vKPEXCeG+0qKnkox7FJrSIDTmwIpLgFHZzVh5PgL03fc 0b0QUw6B7LzKyskSRKAIAReL9CrrNdQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-1ekFTghOMeOIsWciWPSsgw-1; Mon, 17 Aug 2026 05:00:09 -0400 X-MC-Unique: 1ekFTghOMeOIsWciWPSsgw-1 X-Mimecast-MFC-AGG-ID: 1ekFTghOMeOIsWciWPSsgw_1786957208 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-495529a93f9so30955805e9.3 for ; Mon, 17 Aug 2026 02:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1786957208; x=1787562008; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3OSbmtJaxuAXKm9wxovJJHMJ29/ztwYERcUJ/tlgLm4=; b=UI508pk0MLdNRwm3e8EKbog5QY15KnEjF/AIYynAlXxk0y6KLzBlX9J5wAzw2ed83F Cdxxq4ufzdZ5x/JNJcSzUTQG3TLrKSD9wo7YdNTu7fmUk6UDVEajBa6DYhg/08To7LjP cgKsivzi8uyU+DRqo0LqehUDlNMog+0ZNaiFLkxwiHQ4UZhFxOota9facMJe/rg/SqHf mwHhH/QmNFcgw8ehsAXr++Hh4tUbl17XPXo4Kd+mNigc6cQ7EanOJjm+TrWsfTgR6y/J 1xD7rN0hFzFXjctquyHw5VNMntSc+NPHXFqfZTz+2zYKnF8H7s1kxI+ZJ6Umz0KMQ+2y fTvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786957208; x=1787562008; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3OSbmtJaxuAXKm9wxovJJHMJ29/ztwYERcUJ/tlgLm4=; b=pCmE6JqXK5Wrdx8HC4JDerRRkqBotD83YWd5h3OpLqT1xhAaKsyzcyWiS3WvNDKfAS 72H8nskzAIUb2V+FnIxlyA1QXeeXy1ixAACfoc3E4uurhK/3/3081Sw5gtfOdbt8VR46 0GWDg46fWxL8Lj4E8ngXtmNkf95g2dgEDSnwcGnqJTNPEcZ/VmLcqXxhZIPRkNItYr8c M6yKpi1Z+2fxCdhuj4/5VPsVxhIbKfh2wufW6Kk++e4GXVKRelLUohlqagfjHo2D39PH zuxuEOU1z8pgfluE+BfCVdiblk5skSskxhVN5FPdKZZ98D+UGmb4q4Qjq0l3R5Qj0Rdj rfSA== X-Forwarded-Encrypted: i=1; AHgh+RoHJdv/RXmGNi4DRD133bD23PLu4BEVw5msTmmUtQwtMW/GwPuRv2qB7RIB/pzG5Mdnqq7v55ep9GTqLlE=@vger.kernel.org X-Gm-Message-State: AOJu0YyIWae1DQH7Z6MdjDiVbcRMoSM8b1GEDMq4qN+PMdw/pLWrslX1 USZdRid+jaNiBh5y598ZGgRxzSzkEy/I8n7f+2o83BjidzwvPgk9PWqJ15ziArODuzx7Vzyq3H5 T0t65PE3RB3NusnX4KlWhVlIimK2qHvcUX+YSqyJK5jGWEy6HU8Hce6R0+m0bchEpyQ== X-Gm-Gg: AR+sD12sPd4ErrO0DffYRpcC7Q5XAtC8KcspGBGz5EBhWWT+V0l1TMyI84br9B+SbHd 9sQLi1xVQVsyK6TKUMlIjnZIlRAh2SdrK3bY+DSNIX+KLTvFdt+SkvMDo0YdWlSbZvEvL8Qti82 F6i1+CZv12qmDOpxNBCe64xIvqevbGXJ6OwfBbiWMcPFVhndsiVDrUiO0zUHo3nXasV+r1GXv/B q85eYA4/KzVz5Rg8al9Hw2mFN+ZsJAD3s/vUoDRZ+cD34+qrQta+uxEKA9MtOUJ15ky2h3KXZ4O Apim2CHbatxu9w+0oDT+Zr8GvX0OKT3VeY1VHZMApFdrpYVeh15TdabeKai0jxnzEaWOr35H05x W1nmZkzrOuw4nd9xZxXwUEEC1nYCdPbfeR5cox4r/cvs= X-Received: by 2002:a05:600c:564a:b0:498:ff3:71ed with SMTP id 5b1f17b1804b1-49987993affmr279071105e9.17.1786957207612; Mon, 17 Aug 2026 02:00:07 -0700 (PDT) X-Received: by 2002:a05:600c:564a:b0:498:ff3:71ed with SMTP id 5b1f17b1804b1-49987993affmr279069755e9.17.1786957206839; Mon, 17 Aug 2026 02:00:06 -0700 (PDT) Received: from ?IPV6:2a01:e0a:f0e:9070:527b:9dff:feef:3874? ([2a01:e0a:f0e:9070:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482a5a31572sm2267922f8f.5.2026.08.17.02.00.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Aug 2026 02:00:05 -0700 (PDT) Message-ID: Date: Mon, 17 Aug 2026 11:00:03 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/4] KVM: arm64: vgic-its: Don't dereference a NULL collection on ITT save Content-Language: en-US To: Fuad Tabba Cc: Marc Zyngier , Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Will Deacon , Sascha Bischoff , Sebastian Ene , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20260807104102.2410744-1-fuad.tabba@linux.dev> <20260807104102.2410744-2-fuad.tabba@linux.dev> <0ce5e496-a067-48fd-80d2-94fe9981d505@redhat.com> From: Eric Auger In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Fuad, On 8/15/26 2:18 AM, Fuad Tabba wrote: > Hi Eric, > > On Fri, 14 Aug 2026 at 14:36, Eric Auger wrote: >> >> Hi Fuad, >> >> On 8/7/26 12:40 PM, Fuad Tabba wrote: >>> MAPC with V=0 drops ite->collection but leaves the ITE on the device's >>> ITT list, and vgic_its_save_ite() dereferences it unconditionally. A >>> guest that issues MAPD, MAPTI and then MAPC(V=0) therefore oopses the >>> host when the VMM issues KVM_DEV_ARM_ITS_SAVE_TABLES to migrate it. >> Thank you for fixing this bug! >>> That sequence is UNPREDICTABLE per the architecture, but KVM already >>> handles the resulting state in the translate, MOVI and DISCARD paths. >> Maybe: "its_is_collection_mapped() already checks the collection is non >> null in translate, movi and discard" > > Agreed, that's more accurate. This went into kvmarm/next on the 8th > [1], so it's the comment rather than the commit message I can still > fix. sorry I did not notice. That's not a big deal either. > > ... > >>> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c >>> index 36ab3e4929154..ed281fbf008b9 100644 >>> --- a/arch/arm64/kvm/vgic/vgic-its.c >>> +++ b/arch/arm64/kvm/vgic/vgic-its.c >>> @@ -2119,6 +2119,14 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, >>> u32 next_offset; >>> u64 val; >>> >>> + /* >>> + * MAPC with V=0 keeps the ITEs mapped but drops their collection, >>> + * and with it the ICID. Save a zeroed entry, which the restore path >>> + * reads back as invalid. >> in >> >> https://lore.kernel.org/all/CA+EHjTymdanCKoQO3ATmUZ=7Ph2wv4ES8SfkSsTgmOYAYBWayQ@mail.gmail.com/ >> >> you also mentionned this can also happen on clearing >> GITS_BASER.Valid clear. So maybe don't specifically focus on MAPC >> in in the comment. > > Yes, and the BASER case is the one that justifies the check: MAPC(V=0) > is UNPREDICTABLE, so it could be answered by dropping the ITEs, while > clearing GITS_BASER.Valid on a disabled ITS cannot. The comment > names only the case that doesn't. I'll send a patch on top to reword > it. OK > >> >> >>> + */ >>> + if (!ite->collection) >>> + return vgic_its_write_entry_lock(its, gpa, 0ULL, ite); >> I would rather squash 4/4 here to emphasize we are unlinking that entry >> from the scan chain. > > 1/4 has Cc: stable and 4/4 isn't a fix, so I kept them apart. 4/4 ok makes sense > doesn't make the write unnecessary either: an orphaned ITE with no > valid predecessor is read directly, regardless of the offsets. indeed > >> Besides I also wonder if we should directly remove those entries from >> the &device->itt_head on MAPC and GITS_BASER.Valid reset. > > For MAPC(V=0) I think it works, and it would stop the event slot being > wedged: an orphaned ITE today can't be DISCARD-ed or remapped with > MAPTI. But the ITT entry has to be zeroed with it, the way DISCARD > does, or an earlier save's entry stays in the slot and restore fails > find_collection() on the destination. Oliver suggested the same on v1 > [2]. > > That pairing is what makes me doubt the BASER reset. There we would be > zeroing every ITE of every mapped device from the GITS_BASER write > handler, which is an unbounded number of guest memory writes on a > register access, and unlike MAPC(V=0) that write isn't UNPREDICTABLE > to begin with. Yes effectively this would imply to null the associated ITEs... On the other end, overwriting GITS_BASER while V already set looks rather far fetched but well ... Thanks Eric > Cheers, > /fuad > > [1] https://lore.kernel.org/all/178621413198.380376.1272590130654213471.b4-ty@kernel.org/ > [2] https://lore.kernel.org/all/anQQ3dcbk72N1g1a@kernel.org/ > >> Thanks >> >> Eric> next_offset = compute_next_eventid_offset(&dev->itt_head, ite); >>> val = ((u64)next_offset << KVM_ITS_ITE_NEXT_SHIFT) | >>> ((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) | >> >