From patchwork Wed May 13 17:31:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 186667 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp656954ilb; Wed, 13 May 2020 10:33:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhsI1dYBBOf/a6mhmCWd59Hc8mp2bNp95UPqRs3HtYPGoky/hJk9Smoh5pU5MEk6kc9T+E X-Received: by 2002:a05:620a:951:: with SMTP id w17mr787391qkw.371.1589391191549; Wed, 13 May 2020 10:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589391191; cv=none; d=google.com; s=arc-20160816; b=NsF2KsN+n9VF0EA/KPZaxlBNxrhTAMpmrMME09WfiYpkbQFd2/39GuLMK7ayyUZLg+ T0lxUnO7z00uySKohfR5XwP4qwRVdvq1hxUoPr7LBlmdeEf1mSR/qRWVZmyh/hUp6Q4H 38y1wVmJamAHhi8ik3tZ9L1rahfk8JD8ixzr7DjJ6G6ga7/2bUCO+Dbflt335b0LOSnl /teb6o1PcKegemt0wNFYTj9s4KbcifL0TgwiXuuIgPPpUyaUL90r4ao/SFIBeQ/MGPQq fTZGma3IxBYMgqGyMHekKk/CFdmKYzWNY4HY2XiF2x5hJGU8P0/dyFrXCiAP22OBHpqc +vcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Gdil8t+xOr7TCjqgJyVIpfNS5QGic/4oGQPhUYY1lwY=; b=Mpdtnprh7ISXHPonPHfm92Rc0ds3NzTazjLgj4qWGROCVgElB1wLVwaumu4gL4tMCS /Xu/aeQ29GGR3gU/N6jt4YH0aCRT00um/u8Or6z6TwedN6Pe1ymcDQVZAcNvUdLD6nGE smhmeGB3dxgpyLflTt7xzK0S34zSKzB1eb698vDcHnfyptR3CTqM5xgKCpc6STTO7o6o uz1mKFmGOyhBb6VyNs5vjJM4izZN5Hn6CJrksiUmElmNYeM/kUWgEgshT7F/0JU/IIYF FMxlQnC4wh4UG9DRRgOUkHdLVFlEqL19Q9XBD4vZpzDwgMaTT0KRkLiEaYV9nKe7BTr/ 76Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Mk0PGW4B; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 17si93846qkd.20.2020.05.13.10.33.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 May 2020 10:33:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Mk0PGW4B; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYvFm-00057y-Ql for patch@linaro.org; Wed, 13 May 2020 13:33:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYvEq-0004jR-2C for qemu-devel@nongnu.org; Wed, 13 May 2020 13:32:12 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYvEp-0007m8-4A for qemu-devel@nongnu.org; Wed, 13 May 2020 13:32:11 -0400 Received: by mail-wr1-x444.google.com with SMTP id w7so401788wre.13 for ; Wed, 13 May 2020 10:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gdil8t+xOr7TCjqgJyVIpfNS5QGic/4oGQPhUYY1lwY=; b=Mk0PGW4BIra3cS2PmzSYNrVkdPGBRV8SVZaCqfq3vq6bVcstAaROI1pszAwikYGSsE TABTuaPO8dcIPnw+KIVPuayAZ74+Ee8C5we2skVc3UidC2FUrVbdGFYAyK6kPoAcs/sa 63FiyyTPadcyjIAMJnG30EuPaHzMowRQwdLDf8a2t0ywzKWQtcwCsBQsKQyIUUhAP7ce M2W44Feha5Jb5GYaCOntV4Ufc5SKrdFABO3/cjsc+twW2Cbnm2DR5b6aWEQrqGvu91/i 77VNQd8UrIF9y5DpHeBLPiUi4QDBlIy1xK9cJSvtfzgddm0yosxxqmm9APmdQ+wJdJqe X5dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gdil8t+xOr7TCjqgJyVIpfNS5QGic/4oGQPhUYY1lwY=; b=LrsLrXydAr7uwuqsxmOjbw3oWDFmCFq8ZHfVyFwjMlgH58V6Rn98nHXy09Wn+3wvtp DpPK/l1gAIibMR5wg48eVclkphji72u9f0dyDfocXCfwMwgpuAkNpsGhZ6rwK1pdGVgF 3oMPQv0GSgAO/2yp6vqehAOk+T1erdiW1pYTcNAERzob+e6PVeWtrAdoAn+rP16mvWWn k7gijUOetfPebiL7t8BXoOdOnWLZW1dqTpn4sq0glBycdF4R2dXqdOVjPAGXQeHINY5U 8Fc7u9WGsEX+VGteYh37JoVeFzNdlzHE0hgKKcsgkf2WeQrZeQu9jC3gnncQFG75MkVN 5Vcw== X-Gm-Message-State: AOAM5314F65i2Ufv98+kLwQR9LDQxS3DN1mEqip5FobSn9hVOp6fBpGV boeUv+PdKht3pI/x65zqFLZr9Rq7h3I= X-Received: by 2002:adf:97d9:: with SMTP id t25mr438902wrb.176.1589391129690; Wed, 13 May 2020 10:32:09 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id b14sm25207574wmb.18.2020.05.13.10.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 10:32:08 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5727D1FF91; Wed, 13 May 2020 18:32:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 5/8] cpus-common: ensure auto-assigned cpu_indexes don't clash Date: Wed, 13 May 2020 18:31:57 +0100 Message-Id: <20200513173200.11830-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200513173200.11830-1-alex.bennee@linaro.org> References: <20200513173200.11830-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Nikolay Igotti , Igor Mammedov , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Basing the cpu_index on the number of currently allocated vCPUs fails when vCPUs aren't removed in a LIFO manner. This is especially true when we are allocating a cpu_index for each guest thread in linux-user where there is no ordering constraint on their allocation and de-allocation. [I've dropped the assert which is there to guard against out-of-order removal as this should probably be caught higher up the stack. Maybe we could just ifdef CONFIG_SOFTTMU it?] Signed-off-by: Alex Bennée Cc: Nikolay Igotti Cc: Paolo Bonzini Cc: Igor Mammedov Cc: Eduardo Habkost --- cpus-common.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) -- 2.20.1 Acked-by: Igor Mammedow diff --git a/cpus-common.c b/cpus-common.c index 55d5df89237..5a7d2f6132b 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -61,13 +61,14 @@ static bool cpu_index_auto_assigned; static int cpu_get_free_index(void) { CPUState *some_cpu; - int cpu_index = 0; + int max_cpu_index = 0; cpu_index_auto_assigned = true; CPU_FOREACH(some_cpu) { - cpu_index++; + max_cpu_index = MAX(some_cpu->cpu_index, max_cpu_index); } - return cpu_index; + max_cpu_index++; + return max_cpu_index; } void cpu_list_add(CPUState *cpu) @@ -90,8 +91,6 @@ void cpu_list_remove(CPUState *cpu) return; } - assert(!(cpu_index_auto_assigned && cpu != QTAILQ_LAST(&cpus))); - QTAILQ_REMOVE_RCU(&cpus, cpu, node); cpu->cpu_index = UNASSIGNED_CPU_INDEX; }