Skip to content

Commit

Permalink
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging
Browse files Browse the repository at this point in the history
* target/i386: use TSTEQ/TSTNE
* move Coverity builds to Gitlab CI
* fix two memory leaks
* bug fixes

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmXrJjIUHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroPYvggAjKfN1P25JIOZnllky44lY1A7ABtw
# ufMc6u5+U7rP7LjhG4HWL5anpOLyeJICMxyl7dY1BO8NMA+zb8x1sYWEnDFbdL2C
# vB2/MfXVPaVHfdv+4qqoLoJYSQPwfJ90YMdhBIqJ9NtrehdeElcCw0OQE+Od6zM7
# pLlqkRiIjR4HZPu/E/LyBPCo0xZxj1MMdWtsMsapxjsphuLgWznubnRl/Sht5+g6
# x6h8c1MQooKo9Us/GW8QTjIVPgPdmXQMdghmxFYnakpl9PLpHdGizjqmMSEVrYOf
# 5TMmK8nWLLiKYoFHjsLOC93J1nZVdfGOFYq13e2c3fQ8rCbIvogx2n1e3g==
# =hvAl
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 08 Mar 2024 14:52:34 GMT
# gpg:                using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg:                issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>" [full]
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4  E2F7 7E15 100C CD36 69B1
#      Subkey fingerprint: F133 3857 4B66 2389 866C  7682 BFFB D25F 78C7 AE83

* tag 'for-upstream' of https://gitlab.com/bonzini/qemu:
  gitlab-ci: add manual job to run Coverity
  run-coverity-scan: add --check-upload-only option
  target/i386: remove mask from CCPrepare
  target/i386: use TSTEQ/TSTNE to check flags
  target/i386: use TSTEQ/TSTNE to test low bits
  mips: do not list individual devices from configs/
  oslib-posix: fix memory leak in touch_all_pages
  hw/intc/apic: fix memory leak
  hw/scsi/lsi53c895a: stop script on phase mismatch
  meson: Remove --warn-common ldflag
  system/qdev-monitor: move drain_call_rcu call under if (!dev) in qmp_device_add()
  hw/scsi/lsi53c895a: add timer to scripts processing

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Mar 8, 2024
2 parents ba4a5d1 + 47791be commit b507dec
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 152 deletions.
4 changes: 4 additions & 0 deletions .gitlab-ci.d/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ variables:
- if: '$CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM && $CI_COMMIT_TAG'
when: never

# Scheduled runs on mainline don't get pipelines except for the special Coverity job
- if: '$CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM && $CI_PIPELINE_SOURCE == "schedule"'
when: never

# Cirrus jobs can't run unless the creds / target repo are set
- if: '$QEMU_JOB_CIRRUS && ($CIRRUS_GITHUB_REPO == null || $CIRRUS_API_TOKEN == null)'
when: never
Expand Down
39 changes: 38 additions & 1 deletion .gitlab-ci.d/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ build-without-defaults:
--disable-pie
--disable-qom-cast-debug
--disable-strip
TARGETS: avr-softmmu mips64-softmmu s390x-softmmu sh4-softmmu
TARGETS: avr-softmmu s390x-softmmu sh4-softmmu
sparc64-softmmu hexagon-linux-user i386-linux-user s390x-linux-user
MAKE_CHECK_ARGS: check

Expand Down Expand Up @@ -729,3 +729,40 @@ pages:
- public
variables:
QEMU_JOB_PUBLISH: 1

coverity:
image: $CI_REGISTRY_IMAGE/qemu/fedora:$QEMU_CI_CONTAINER_TAG
stage: build
allow_failure: true
timeout: 3h
needs:
- job: amd64-fedora-container
optional: true
before_script:
- dnf install -y curl wget
script:
# would be nice to cancel the job if over quota (https://gitlab.com/gitlab-org/gitlab/-/issues/256089)
# for example:
# curl --request POST --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "${CI_SERVER_URL}/api/v4/projects/${CI_PROJECT_ID}/jobs/${CI_JOB_ID}/cancel
- 'scripts/coverity-scan/run-coverity-scan --check-upload-only || { exitcode=$?; if test $exitcode = 1; then
exit 0;
else
exit $exitcode;
fi; };
scripts/coverity-scan/run-coverity-scan --update-tools-only > update-tools.log 2>&1 || { cat update-tools.log; exit 1; };
scripts/coverity-scan/run-coverity-scan --no-update-tools'
rules:
- if: '$COVERITY_TOKEN == null'
when: never
- if: '$COVERITY_EMAIL == null'
when: never
# Never included on upstream pipelines, except for schedules
- if: '$CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM && $CI_PIPELINE_SOURCE == "schedule"'
when: on_success
- if: '$CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM'
when: never
# Forks don't get any pipeline unless QEMU_CI=1 or QEMU_CI=2 is set
- if: '$QEMU_CI != "1" && $QEMU_CI != "2"'
when: never
# Always manual on forks even if $QEMU_CI == "2"
- when: manual
4 changes: 4 additions & 0 deletions .gitlab-ci.d/opensbi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
- if: '$QEMU_CI == "1" && $CI_PROJECT_NAMESPACE != "qemu-project" && $CI_COMMIT_MESSAGE =~ /opensbi/i'
when: manual

# Scheduled runs on mainline don't get pipelines except for the special Coverity job
- if: '$CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM && $CI_PIPELINE_SOURCE == "schedule"'
when: never

# Run if any files affecting the build output are touched
- changes:
- .gitlab-ci.d/opensbi.yml
Expand Down
28 changes: 4 additions & 24 deletions configs/devices/mips-softmmu/common.mak
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
# Common mips*-softmmu CONFIG defines

CONFIG_ISA_BUS=y
CONFIG_PCI=y
CONFIG_PCI_DEVICES=y
CONFIG_VGA_ISA=y
CONFIG_VGA_MMIO=y
CONFIG_VGA_CIRRUS=y
CONFIG_VMWARE_VGA=y
CONFIG_SERIAL=y
CONFIG_SERIAL_ISA=y
CONFIG_PARALLEL=y
CONFIG_I8254=y
CONFIG_PCSPK=y
CONFIG_PCKBD=y
CONFIG_FDC=y
CONFIG_I8257=y
CONFIG_IDE_ISA=y
CONFIG_PFLASH_CFI01=y
CONFIG_I8259=y
CONFIG_MC146818RTC=y
CONFIG_MIPS_CPS=y
CONFIG_MIPS_ITU=y
# Uncomment the following lines to disable these optional devices:
# CONFIG_PCI_DEVICES=n
# CONFIG_TEST_DEVICES=n

CONFIG_MALTA=y
CONFIG_PCNET_PCI=y
CONFIG_MIPSSIM=y
CONFIG_SMBUS_EEPROM=y
CONFIG_TEST_DEVICES=y
3 changes: 0 additions & 3 deletions configs/devices/mips64el-softmmu/default.mak
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
include ../mips-softmmu/common.mak
CONFIG_FULOONG=y
CONFIG_LOONGSON3V=y
CONFIG_ATI_VGA=y
CONFIG_RTL8139_PCI=y
CONFIG_JAZZ=y
CONFIG_VT82C686=y
CONFIG_MIPS_BOSTON=y
2 changes: 1 addition & 1 deletion hw/display/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ config VGA_MMIO

config VMWARE_VGA
bool
default y if PCI_DEVICES && PC_PCI
default y if PCI_DEVICES && (PC_PCI || MIPS)
depends on PCI
select VGA

Expand Down
6 changes: 2 additions & 4 deletions hw/intc/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,13 @@ static void apic_deliver_irq(uint32_t dest, uint8_t dest_mode,
uint8_t delivery_mode, uint8_t vector_num,
uint8_t trigger_mode)
{
uint32_t *deliver_bitmask = g_malloc(max_apic_words * sizeof(uint32_t));
g_autofree uint32_t *deliver_bitmask = g_new(uint32_t, max_apic_words);

trace_apic_deliver_irq(dest, dest_mode, delivery_mode, vector_num,
trigger_mode);

apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode);
apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode);
g_free(deliver_bitmask);
}

bool is_x2apic_mode(DeviceState *dev)
Expand Down Expand Up @@ -662,7 +661,7 @@ static void apic_deliver(DeviceState *dev, uint32_t dest, uint8_t dest_mode,
APICCommonState *s = APIC(dev);
APICCommonState *apic_iter;
uint32_t deliver_bitmask_size = max_apic_words * sizeof(uint32_t);
uint32_t *deliver_bitmask = g_malloc(deliver_bitmask_size);
g_autofree uint32_t *deliver_bitmask = g_new(uint32_t, max_apic_words);
uint32_t current_apic_id;

if (is_x2apic_mode(dev)) {
Expand Down Expand Up @@ -708,7 +707,6 @@ static void apic_deliver(DeviceState *dev, uint32_t dest, uint8_t dest_mode,
}

apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode);
g_free(deliver_bitmask);
}

static bool apic_check_pic(APICCommonState *s)
Expand Down
20 changes: 19 additions & 1 deletion hw/mips/Kconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
config MALTA
bool
imply PCNET_PCI
imply PCI_DEVICES
imply TEST_DEVICES
select FDC37M81X
select GT64120
select MIPS_CPS
select PIIX
select PFLASH_CFI01
select SERIAL
select SMBUS_EEPROM

config MIPSSIM
bool
Expand Down Expand Up @@ -31,17 +38,26 @@ config JAZZ

config FULOONG
bool
imply PCI_DEVICES
imply TEST_DEVICES
imply ATI_VGA
imply RTL8139_PCI
select PCI_BONITO
select SMBUS_EEPROM
select VT82C686

config LOONGSON3V
bool
imply PCI_DEVICES
imply TEST_DEVICES
imply VIRTIO_PCI
imply VIRTIO_NET
imply VIRTIO_VGA
imply QXL if SPICE
imply USB_OHCI_PCI
select SERIAL
select GOLDFISH_RTC
select LOONGSON_LIOINTC
select PCI_DEVICES
select PCI_EXPRESS_GENERIC_BRIDGE
select MSI_NONBROKEN
select FW_CFG_MIPS
Expand All @@ -53,6 +69,8 @@ config MIPS_CPS

config MIPS_BOSTON
bool
imply PCI_DEVICES
imply TEST_DEVICES
select FITLOADER
select MIPS_CPS
select PCI_EXPRESS_XILINX
Expand Down
59 changes: 45 additions & 14 deletions hw/scsi/lsi53c895a.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static const char *names[] = {
#define LSI_TAG_VALID (1 << 16)

/* Maximum instructions to process. */
#define LSI_MAX_INSN 10000
#define LSI_MAX_INSN 100

typedef struct lsi_request {
SCSIRequest *req;
Expand All @@ -205,6 +205,7 @@ enum {
LSI_WAIT_RESELECT, /* Wait Reselect instruction has been issued */
LSI_DMA_SCRIPTS, /* processing DMA from lsi_execute_script */
LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
LSI_WAIT_SCRIPTS, /* SCRIPTS stopped because of instruction count limit */
};

enum {
Expand All @@ -224,6 +225,7 @@ struct LSIState {
MemoryRegion ram_io;
MemoryRegion io_io;
AddressSpace pci_io_as;
QEMUTimer *scripts_timer;

int carry; /* ??? Should this be an a visible register somewhere? */
int status;
Expand Down Expand Up @@ -415,6 +417,7 @@ static void lsi_soft_reset(LSIState *s)
s->sbr = 0;
assert(QTAILQ_EMPTY(&s->queue));
assert(!s->current);
timer_del(s->scripts_timer);
}

static int lsi_dma_40bit(LSIState *s)
Expand Down Expand Up @@ -570,8 +573,9 @@ static inline void lsi_set_phase(LSIState *s, int phase)
s->sstat1 = (s->sstat1 & ~PHASE_MASK) | phase;
}

static void lsi_bad_phase(LSIState *s, int out, int new_phase)
static int lsi_bad_phase(LSIState *s, int out, int new_phase)
{
int ret = 0;
/* Trigger a phase mismatch. */
if (s->ccntl0 & LSI_CCNTL0_ENPMJ) {
if ((s->ccntl0 & LSI_CCNTL0_PMJCTL)) {
Expand All @@ -584,8 +588,10 @@ static void lsi_bad_phase(LSIState *s, int out, int new_phase)
trace_lsi_bad_phase_interrupt();
lsi_script_scsi_interrupt(s, LSI_SIST0_MA, 0);
lsi_stop_script(s);
ret = 1;
}
lsi_set_phase(s, new_phase);
return ret;
}


Expand Down Expand Up @@ -789,15 +795,18 @@ static int lsi_queue_req(LSIState *s, SCSIRequest *req, uint32_t len)
static void lsi_command_complete(SCSIRequest *req, size_t resid)
{
LSIState *s = LSI53C895A(req->bus->qbus.parent);
int out;
int out, stop = 0;

out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
trace_lsi_command_complete(req->status);
s->status = req->status;
s->command_complete = 2;
if (s->waiting && s->dbc != 0) {
/* Raise phase mismatch for short transfers. */
lsi_bad_phase(s, out, PHASE_ST);
stop = lsi_bad_phase(s, out, PHASE_ST);
if (stop) {
s->waiting = 0;
}
} else {
lsi_set_phase(s, PHASE_ST);
}
Expand All @@ -807,7 +816,9 @@ static void lsi_command_complete(SCSIRequest *req, size_t resid)
lsi_request_free(s, s->current);
scsi_req_unref(req);
}
lsi_resume_script(s);
if (!stop) {
lsi_resume_script(s);
}
}

/* Callback to indicate that the SCSI layer has completed a transfer. */
Expand Down Expand Up @@ -1127,6 +1138,12 @@ static void lsi_wait_reselect(LSIState *s)
}
}

static void lsi_scripts_timer_start(LSIState *s)
{
trace_lsi_scripts_timer_start();
timer_mod(s->scripts_timer, qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + 500);
}

static void lsi_execute_script(LSIState *s)
{
PCIDevice *pci_dev = PCI_DEVICE(s);
Expand All @@ -1136,29 +1153,29 @@ static void lsi_execute_script(LSIState *s)
int insn_processed = 0;
static int reentrancy_level;

if (s->waiting == LSI_WAIT_SCRIPTS) {
timer_del(s->scripts_timer);
s->waiting = LSI_NOWAIT;
}

reentrancy_level++;

s->istat1 |= LSI_ISTAT1_SRUN;
again:
/*
* Some windows drivers make the device spin waiting for a memory location
* to change. If we have executed more than LSI_MAX_INSN instructions then
* assume this is the case and force an unexpected device disconnect. This
* is apparently sufficient to beat the drivers into submission.
* assume this is the case and start a timer. Until the timer fires, the
* host CPU has a chance to run and change the memory location.
*
* Another issue (CVE-2023-0330) can occur if the script is programmed to
* trigger itself again and again. Avoid this problem by stopping after
* being called multiple times in a reentrant way (8 is an arbitrary value
* which should be enough for all valid use cases).
*/
if (++insn_processed > LSI_MAX_INSN || reentrancy_level > 8) {
if (!(s->sien0 & LSI_SIST0_UDC)) {
qemu_log_mask(LOG_GUEST_ERROR,
"lsi_scsi: inf. loop with UDC masked");
}
lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
lsi_disconnect(s);
trace_lsi_execute_script_stop();
s->waiting = LSI_WAIT_SCRIPTS;
lsi_scripts_timer_start(s);
reentrancy_level--;
return;
}
Expand Down Expand Up @@ -2197,6 +2214,9 @@ static int lsi_post_load(void *opaque, int version_id)
return -EINVAL;
}

if (s->waiting == LSI_WAIT_SCRIPTS) {
lsi_scripts_timer_start(s);
}
return 0;
}

Expand Down Expand Up @@ -2294,6 +2314,15 @@ static const struct SCSIBusInfo lsi_scsi_info = {
.cancel = lsi_request_cancelled
};

static void scripts_timer_cb(void *opaque)
{
LSIState *s = opaque;

trace_lsi_scripts_timer_triggered();
s->waiting = LSI_NOWAIT;
lsi_execute_script(s);
}

static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
{
LSIState *s = LSI53C895A(dev);
Expand All @@ -2313,6 +2342,7 @@ static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
"lsi-ram", 0x2000);
memory_region_init_io(&s->io_io, OBJECT(s), &lsi_io_ops, s,
"lsi-io", 256);
s->scripts_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, scripts_timer_cb, s);

/*
* Since we use the address-space API to interact with ram_io, disable the
Expand All @@ -2337,6 +2367,7 @@ static void lsi_scsi_exit(PCIDevice *dev)
LSIState *s = LSI53C895A(dev);

address_space_destroy(&s->pci_io_as);
timer_del(s->scripts_timer);
}

static void lsi_class_init(ObjectClass *klass, void *data)
Expand Down
2 changes: 2 additions & 0 deletions hw/scsi/trace-events
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ lsi_execute_script_stop(void) "SCRIPTS execution stopped"
lsi_awoken(void) "Woken by SIGP"
lsi_reg_read(const char *name, int offset, uint8_t ret) "Read reg %s 0x%x = 0x%02x"
lsi_reg_write(const char *name, int offset, uint8_t val) "Write reg %s 0x%x = 0x%02x"
lsi_scripts_timer_triggered(void) "SCRIPTS timer triggered"
lsi_scripts_timer_start(void) "SCRIPTS timer started"

# virtio-scsi.c
virtio_scsi_cmd_req(int lun, uint32_t tag, uint8_t cmd) "virtio_scsi_cmd_req lun=%u tag=0x%x cmd=0x%x"
Expand Down

0 comments on commit b507dec

Please sign in to comment.