From patchwork Wed May 27 14:54:53 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: 187279 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp1193734ilb; Wed, 27 May 2020 07:58:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/4RouGqIZoEp4RkI9MIzdRa9P/VeL0N7wRAZAbE1TYaxH1ZfvJznAAIjPJrqGpJ9zErly X-Received: by 2002:a25:76c5:: with SMTP id r188mr11630140ybc.71.1590591503146; Wed, 27 May 2020 07:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590591503; cv=none; d=google.com; s=arc-20160816; b=NYbQj+SfzS8cIFg8PL+PA+OFEmHDiOGYiPcEQL4E5/gagtusCLgFocOB6x1WzkhUDD PoT2pbdvVZcnCJSjU6+HuR0c0OBXuxEF8I9xBaXhV0O+CF7I4ZnR8Azv6I9rYEF5//GN HAA6nszC4cBEJFhJbU8ppWyzNeJjxcxuzW8wvQXfqFwoSQrLNyIqd+t9I4l380uMERRb HkZD46bOpGY5WkI3LsQMS5GyKGocnZJ6j/VkgY1erJk8MgN4tXOoxLjol9TfnGDY19nl HJ85O0lbQhM3RivA1vCOQ2cA5qIAaOt1XIbbVUtcPjakjmJGGX1YojanJO47CUqOCk6c wq/g== 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=aitRg9If761W1gcoFA+t9rMfX6i5VN1JLB5FFhcpUdo=; b=mU3Als9a8qy93HMtA6DEqWhAIOc9BUWeqxm9AlTFkYXurdo+3KaKNuL3Fw8dm2BPdA I3gHCCp7nnaVwqh5xNO/UQZwcMLlAhZE8jtQt5vbZJIArssy1wTlcpJgv5skwR2g78zc GkT32SS+DrriFf+bGUPq4sKu8CxH6WsLzKd/clVvOBanoPKeU1A9UtvsFZWfQj3XFp67 eTaOcrr6cDmunqCgJgEw4yMRXnKbl0RIShDcJHGHkwDzv8hvtc3cEp95mLDoohHLjx8b 8jrMuM7oF1P5mMVs54DWz1zxA36cUy9bZKB4RBTzUtncGHqObrUja42UNq4EmOSnBytt mDeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sOuJUfkk; 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 x28si3040065ybi.330.2020.05.27.07.58.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 May 2020 07:58:23 -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=sOuJUfkk; 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]:59936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdxVe-0008Ey-Kv for patch@linaro.org; Wed, 27 May 2020 10:58:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdxSa-0001wZ-QZ for qemu-devel@nongnu.org; Wed, 27 May 2020 10:55:12 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:43627) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdxSY-0008DY-2f for qemu-devel@nongnu.org; Wed, 27 May 2020 10:55:12 -0400 Received: by mail-wr1-x434.google.com with SMTP id l10so1538000wrr.10 for ; Wed, 27 May 2020 07:55:09 -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=aitRg9If761W1gcoFA+t9rMfX6i5VN1JLB5FFhcpUdo=; b=sOuJUfkkKq21pQOAkTABGqsTn0BnRJRVoham3SoPFFyazh1d0/l6Kt1j7KNJpSJCnA vsO3UNMZmR+0AfTd4CPnSro5JLqPSPVxNoJn1aBHPjDF6WABOwl+xfbc4CmCSCtnPMfs ayHL27lqrTE94Jo1Cm7MCUOkTuC94SDZjqi3DdfpAc4ks5HYAZ15fa3+k26zZhyIqK4z jdzArH3sJW1PLIRAMQgJ+x1h+nRd4xb+sNM1Vs8999uoK18LNKAgkbTwZc5R/VgLxaAU rH4TZS2K63EO0CG61vMUKdziakvYrBrfIELPmFfdnrqoSIF7YSFMOHIUDrUHDGaScQk4 dOhA== 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=aitRg9If761W1gcoFA+t9rMfX6i5VN1JLB5FFhcpUdo=; b=B8+V4fHzQoZtSUe+bSTuzB7I8ilkNrDffOCugTnPdp4c804nxQ42bDTYCswwuAgOwR 2svUDjRWl9fPWKOY3i2pX1XscRaxWfgieDGzgaF5SZxBmyeAX0l7yqdH6aWwXkPrIfsD nXXFAMvFSIRwxfnkYpaPCy9JSWS1VSOjfcb+jleGRKBSi/QwoJgOlGAytu/0e5nGxpO8 8YwLs9+aGyLnuAKOLqKMB+t4Qjh4EOsQYF2DW8aS1GyNHLmBzDFmM3TaVm6vHuHDWheM mkHauKE9IqR5rUGICMii8j+TtsDI5u1pSJQAN0G2Tmu/bI0c84ywJyvWbc60n8dkLLkw z2xA== X-Gm-Message-State: AOAM533dUys3LWqjEtVEBItG5bNYpMTCPU8Mi38SeqOjg/sxahIMPqkL IWpO0tKAoAYSNvrjW0/U22FI3A== X-Received: by 2002:adf:a399:: with SMTP id l25mr24502400wrb.212.1590591308201; Wed, 27 May 2020 07:55:08 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x186sm3268618wmg.8.2020.05.27.07.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 07:55:04 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 001111FF99; Wed, 27 May 2020 15:54:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 10/12] cpus-common: ensure auto-assigned cpu_indexes don't clash Date: Wed, 27 May 2020 15:54:53 +0100 Message-Id: <20200527145455.2550-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527145455.2550-1-alex.bennee@linaro.org> References: <20200527145455.2550-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x434.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 , Richard Henderson , qemu-devel@nongnu.org, Igor Mammedow , 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 Reviewed-by: Richard Henderson Acked-by: Igor Mammedow Cc: Nikolay Igotti Cc: Paolo Bonzini Cc: Eduardo Habkost Message-Id: <20200520140541.30256-13-alex.bennee@linaro.org> -- 2.20.1 diff --git a/cpus-common.c b/cpus-common.c index 55d5df89237..70a9d12981a 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -61,13 +61,15 @@ 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++; + if (some_cpu->cpu_index >= max_cpu_index) { + max_cpu_index = some_cpu->cpu_index + 1; + } } - return cpu_index; + return max_cpu_index; } void cpu_list_add(CPUState *cpu) @@ -90,8 +92,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; }